Since a while any python manage.py command that requires an input (removing null=True without providing default, recollecting static files...) does not accept said input. when I press enter it simply displays the carriage return char ^M in the console. I have no Idea how to debug this, as ctrl+ c simply gives tracebacks like these:
./manage.py makemigrations
You are trying to change the nullable field 'package' on company to non-nullable without a default; we cannot do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Ignore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)
3) Quit, and let me add a default in models.py
Select an option: 1^M^M^M^C^CKeyboardInterrupt
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 177, in handle
migration_name=self.migration_name,
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 47, in changes
changes = self._detect_changes(convert_apps, graph)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 189, in _detect_changes
self.generate_altered_fields()
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 920, in generate_altered_fields
new_default = self.questioner.ask_not_null_alteration(field_name, model_name)
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/db/migrations/questioner.py", line 182, in ask_not_null_alteration
"Quit, and let me add a default in models.py",
File "/Users/mac/.virtualenvs/mindance/lib/python3.6/site-packages/django/db/migrations/questioner.py", line 99, in _choice_input
result = input("Select an option: ")
SystemError: <built-in function input> returned a result with an error set
Any hints on how to approach this issue? I reinstalled my virtualenv. Maybe I should reinstall python?
Versions:
Python 3.6.1
Django==1.11.2
run this command stty sane in the ubuntu terminal first and then try to run the migrate with python manage.py migrate
Related
I am trying to run the following command
python manage.py makemigrations
But, getting the error
ValueError: path is on mount 'C:', start on mount 'F:'
What can be the reason?
complete traceback:-
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 189, in handle
self.write_migration_files(changes)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 207, in write_migration_files
migration_string = os.path.relpath(writer.path)
File "C:\Python34\lib\ntpath.py", line 579, in relpath
raise ValueError(error)
ValueError: path is on mount 'C:', start on mount 'F:'
The error is occurring because Django is trying to find a relative path between 2 directories and they do not exist (since they are on different drives). This issue is mentioned here: https://bugs.python.org/issue7195. But this response helps to understand the problem: https://bugs.python.org/msg94780.
os.relpath does give you a relative path between two directories.
The problem you are encountering is that, on Windows, a relative path
doesn't even exist if the two directories are on different drives
(which is exactly what the error message says).
When I ran into this error, I was trying to make a migration file for my own app that is located on the F: drive. Running:
python.exe .\manage.py makemigrations
had Django scanning for every change. It located a change for djcelery. This is located in a virtual environment on my C: drive.
To fix this, I just added the app name when calling makemigrations:
python.exe .\manage.py makemigrations <<app_name>>
I am using python 3.5 and windows 10, but had the same issue using windows 8, and that is the traceback i get while trying to runserver:
Traceback (most recent call last):
File "C:\Users\noabendor87\documents\otree\manage.py", line 10, in
execute_from_command_line(sys.argv, script_file=file)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\otree\management\cli.py", line
177, in execute_from_command_line
utility.execute()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management__init__
.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 49, in execute
super(Command, self).execute(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 445, in execute
output = self.handle(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 88, in handle
self.run(**options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 97, in run
autoreload.main(self.inner_run, None, options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 336, in main
reloader(wrapped_main_func, args, kwargs)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 307, in python_reloader
exit_code = restart_with_reloader()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 293, in restart_with_reloader
exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
I have already tried following the instructions in the following link:
http://stackoverflow.com/questions/25714826/error-in-manage-py-runserver-with-django-on-windows-8-1
but it did not help.
This is how the lines of code look like:
enter image description here
(Since Im a new user I cannot paste the image to the original post)
Anyone have encountered something similar and have a solution?
I used to have similar problems because of the difficulties with the virtual environment in windows 10. Try running the powershell as an administrator and do "Set-ExecutionPolicy RemoteSigned" or "Set-ExecutionPolicy Unrestricted" if remotesigned does not work. Do this before activating the virtualenv.
first I will like you check the django version you are working with my "type python -m django --version" or "pip freeze". check weather its compatible with the python version on your pc. if it's not install compatible python version. then check weather "init.py" is within your project directory, if not add it to your project directory. then run "Set-ExecutionPolicy -Scope CurrentUser Unrestricted" on your terminal. then run activate your virtualenv, then run "python manage.py runserver"
My current version of python is 2.7.10 and version of Django is 1.9.1, path.py is 8.1.2 but every time when I'm trying to invoke python shell by command:
$ python manage.py shell I'm getting a lot of errors and the ending of them looks like:
Error in sys.excepthook:
Traceback (most recent call last):
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 157, in __call__
report.write(self.make_report(traceback))
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 215, in make_report
rpt_add('BZR revision : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'
Original exception was:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 58, in run_shell
return getattr(self, shell)()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 41, in ipython
ip()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 22, in _ipython_pre_011
shell = IPShell(argv=[])
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Shell.py", line 73, in __init__
debug=debug,shell_class=shell_class)
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\ipmaker.py", line 521, in make_IPython
IP.pre_config_initialization()
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\iplib.py", line 835, in pre_config_initialization
self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Extensions\pickleshare.py", line 53, in __init__
if not self.root.isdir():
TypeError: _isdir() takes exactly 1 argument (0 given)
How can I overcome the problem?
From doing a quick search, it looks like this error happens when both Django and IPython are installed, since apparently Django will attempt to use the IPython shell.
The first resource with someone who had a similar issue:
run python manage.py shell occurs errors
And in the link above, one of the comments on the OP's question suggested looking at this separate thread for answers:
https://superuser.com/questions/318655/error-running-ipython3-on-xp-typeerror-isdir-takes-exactly-1-argument-0-gi
The winning answer says the following:
Finally decided to give this another stab, and managed to get it to
work. The solution is a two-line change in the
ipython-0.11-py3.2.egg\IPython\utils\pickleshare.py file, line 52:
Before:
if not self.root.isdir():
self.root.makedirs()
After:
if not os.path.isdir(self.root):
os.makedirs(self.root)
I am learning Django, and this is my first project. I am working on this project in this tutorial. https://docs.djangoproject.com/en/1.4/intro/tutorial01/
when I ran syncdb command. tables were created. then it asked me if I want to add a superuser, I said yes. then got following error message. I found a few similar questions on stackoverflow, but still canot get it fixed.
(django)feelexit#ubuntu:~/.virtualenvs/testDjango$ ./manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): y
Please enter either "yes" or "no": yes
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 73, in create_superuser
call_command("createsuperuser", interactive=True, database=db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 70, in handle
default_username = get_default_username()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username
default_username = get_system_username()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 85, in get_system_username
return getpass.getuser().decode(locale.getdefaultlocale()[1])
TypeError: decode() argument 1 must be string, not None
Update: I am using ubuntu 12.04. I found a possible solution. add following code to manage.py. however there's a disclaimer next to it "I have no idea if this causes any negative side effects.". I am looking for a better way to fix it.
import os
os.environ.setdefault('LANG','en_US')
This is a bug in the Django code (see the django bug report).
The usual way in the ticket to fix this is to export your shell LANG environment variable.
export LANG="en_US.UTF-8"
That one works for me on a SuSE setup.
export LANG="en_US.UTF-8"
Works for me, but a way to do it by editing manage.py, django-admin creates a different directory structure than it used to and I'm moving files like settings.py, urls.py out of the subfolder.
EDIT: os.environ["LANG"]="en_US.UTF-8" (after doing import os)
I used sys.append to add the path to avoid import errors.
I have new to python and django I am creating poll application and in that application after creating models poll and choice using "South". I want to changer the length of question field from 200 to 300 but I am not able to achieve it even using south as well.
I have run python manage.py schemamigration polls --initial command to create migration file then I make change in poll question field that is (question = models.CharField(max_length=250)) change max_length from 200 to 250.
and the again run python manage.py schemamigration polls --auto this will generate new migration file.
after that all stuff I run python manage.py migrate polls and it shows following error :
C:\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
Running migrations for polls:
- Migrating forwards to 0003_auto__chg_field_poll_question.
> polls:0003_auto__chg_field_poll_question
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = ALTER TABLE `polls_poll` ; []
= ALTER TABLE `polls_poll` MODIFY `question` varchar(200) NOT NULL;; []
= ALTER TABLE `polls_poll` ALTER COLUMN `question` DROP DEFAULT; []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 195,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 222,
in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\south\management\commands\migrate.py", lin
e 109, in handle
ignore_ghosts = ignore_ghosts,
File "C:\Python26\lib\site-packages\south\migration\__init__.py", line 202, in
migrate_app
success = migrator.migrate_many(target, workplan, database)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 220, i
n migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, datab
ase)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 291, i
n migrate_many
result = self.migrate(migration, database)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 125, i
n migrate
result = self.run(migration)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 99, in
run
return self.run_migration(migration)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 81, in
run_migration
migration_function()
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 57, in
<lambda>
return (lambda: direction(orm))
File "C:\mysite\..\mysite\polls\migrations\0003_auto__chg_field_poll_question.
py", line 12, in forwards
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.C
harField')(max_length=250))
File "C:\Python26\lib\site-packages\south\db\generic.py", line 330, in alter_c
olumn
self.delete_foreign_key(table_name, name)
File "C:\Python26\lib\site-packages\south\db\generic.py", line 588, in delete_
foreign_key
constraints = list(self._constraints_affecting_columns(table_name, [column],
"FOREIGN KEY"))
File "C:\Python26\lib\site-packages\south\db\mysql.py", line 140, in _constrai
nts_affecting_columns
""", [db_name, table_name, type])
File "C:\Python26\lib\site-packages\south\db\generic.py", line 134, in execute
cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 19, in e
xecute
return self.cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 84
, in execute
return self.cursor.execute(query, args)
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 168, in execute
if not self._defer_warnings: self._warning_check()
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 82, in _warning_
check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2)
Please help me
0003 Look like :
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Poll.question'
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=250))
def backwards(self, orm):
# Changing field 'Poll.question'
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=200))
Ansh J
Go modify the mysql table from the mysql console already!
python manage.py dbshell
alter table appname_modelname modify `question` varchar(200) NOT NULL;
To be able to answer this question with any certainty you'll need to show migrations 0002 and 0003...
However, it seems to me the resulting exception is simply a problem with MySQL (it cannot find its 'slow log') that creates a warning that is propagated to south, which trips over it.
The problem you're having is not in Django or South, it's in MySQL. MySQL is coughing up the following:
_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2)
and it's panicking the MySQLdb library, which is triggering the bailout, even though it's just a warning.
You need to find out why MySQL is so concerned about its missing slow_log file.
I suspect that you likely have general_log and slow_log frm files within
the mysql database directory, without any corresponding data files. If
this is the case then just 'rm' the general_log.frm and slow_log.frm
files from the mysql database directory, and all these errors should go
away.