When I ran syncdb it gave me a MySQL 150 error, probably related to a FK. However, when I repeatedly run syncdb, it eventually works (the entire trace below). Why is this occurring?
david-MacBook-Pro$ syncdb
Creating tables ...
Creating table jobs_company
Creating table jobs_job
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57e' (errno: 150)")
david-MacBook-Pro:$ syncdb
Creating tables ...
Creating table jobs_jobposition
Creating table jobs_externaljob
Creating table jobs_externalsite
Creating table jobs_sitevisit
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57f' (errno: 150)")
david-MacBook-Pro$ syncdb
Creating tables ...
Creating table jobs_application
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_580' (errno: 150)")
david-MacBook-Pro$ syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
And it works?
It's working because the FKs aren't being created. Analyze the generated SQL to verify why the errors are occurring, and reorder settings.INSTALLED_APPS as appropriate.
Related
I want my project to serve all world cities by using Django-cities.
First and after facing many problems, I made my SQLite accept spacial queries by using advice in this tutorial and this question.
So far I can run "makemigrations" but when I run "migrate" I receive: unexpected metadata layout.
I think the answer to my problem is included in this question but I'm not sure how to apply it in a Django project.
This is full text of the error when I run "migrate":
Applying cities.0001_initial...AddGeometryColumn() error: unexpected metadata layout
CreateSpatialIndex() error: "no such table: geometry_columns"
AddGeometryColumn() error: unexpected metadata layout
CreateSpatialIndex() error: "no such table: geometry_columns"
AddGeometryColumn() error: unexpected metadata layout
CreateSpatialIndex() error: "no such table: geometry_columns"
AddGeometryColumn() error: unexpected metadata layout
CreateSpatialIndex() error: "no such table: geometry_columns"
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Python27\Lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python27\Lib\site-packages\django\db\migrations\executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "C:\Python27\Lib\site-packages\django\db\migrations\executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "C:\Python27\Lib\site-packages\django\db\migrations\migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "C:\Python27\Lib\site-packages\django\db\migrations\operations\fields.py", line 37, in database_forwards
field,
File "C:\Python27\Lib\site-packages\django\contrib\gis\db\backends\spatialite\schema.py", line 102, in add_field
super(SpatialiteSchemaEditor, self).add_field(model, field)
File "C:\Python27\Lib\site-packages\django\db\backends\sqlite3\schema.py", line 160, in add_field
self._remake_table(model, create_fields=[field])
File "C:\Python27\Lib\site-packages\django\db\backends\sqlite3\schema.py", line 128, in _remake_table
self.quote_name(model._meta.db_table),
File "C:\Python27\Lib\site-packages\django\db\backends\schema.py", line 98, in execute
cursor.execute(sql, params)
File "C:\Python27\Lib\site-packages\django\db\backends\utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\Lib\site-packages\django\db\backends\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\Lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\Lib\site-packages\django\db\backends\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\Lib\site-packages\django\db\backends\sqlite3\base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table cities_city__new has no column named location
I am trying to upgrade my django project from django1.8.8 to django1.9.2
Right now I encounter a problem when running my tests with django1.9.2:
python manage.py test
This gives me the following error
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 87, in handle
connection.prepare_database()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 25, in prepare_database
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.InternalError: PostGIS is already installed in schema 'public', uninstall it first
In django1.8 everything works as expected.
Are there any changes in django1.9 and postgis I am not aware of?
It may be due to postgis. Please make sure postgres have the postgis extension.
I could solve this by a hard reset of the databse.
I'm trying to set up django-notifications in my app. I'm following the instructions to install it, which are pretty straight-forward: https://github.com/brantyoung/django-notifications#installation
When I run manage.py migrate notifications I get:
django.db.utils.ProgrammingError: (1146, "Table '{{database}}.notifications_notification' doesn't exist")
I'm at a loss.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 230, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 305, in migrate_many
result = self.migrate(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 134, in migrate
result = self.run(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 115, in run
return self.run_migration(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 85, in run_migration
migration_function()
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 61, in <lambda>
return (lambda: direction(orm))
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/notifications/migrations/0002_auto__add_field_notification_data.py", line 14, in forwards
keep_default=False)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 47, in _cache_clear
return func(self, table, *args, **opts)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 418, in add_column
self.execute(sql)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 282, in execute
cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute
self.errorhandler(self, exc, value)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.ProgrammingError: (1146, "Table 'ownershipdb.notifications_notification' doesn't exist")
You forget to run syncdb before migrating data. The table doesn't exists because it's syncdb that created it, not the migration.
Reference: http://south.readthedocs.org/en/latest/tutorial/part1.html
(If this fails complaining that south_migrationhistory does not exist, you forgot to run syncdb after you installed South.)
In my apps settings.py file (then made available in django.conf.settings) I have specified:
DATABASES = {'default': dj_database_url.parse(os.environ['DATABASE']),
'secondary': dj_database_url.parse(os.environ['SECONDARY_DATABASE'])}
SOUTH_TESTS_MIGRATE = True
But running my tests using ./manage.py test app_name runs the migrations for the default database and creates some of the tables for the secondary database before failing with:
Creating test database for alias 'secondary' ('test_secondary')...
Syncing...
Creating tables ...
Creating table auth_permission
...
Creating table django_admin_log
Installing custom SQL ...
Installing indexes ...
Migrating...
Traceback (most recent call last):
File "./manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 49, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/test/simple.py", line 381, in run_tests
old_config = self.setup_databases()
File "/usr/local/venv/local/lib/python2.7/site-packages/django/test/simple.py", line 317, in setup_databases
self.verbosity, autoclobber=not self.interactive)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/hacks/django_1_0.py", line 100, in wrapper
f(*args, **kwargs)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 271, in create_test_db
load_initial_data=False)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 149, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 99, in handle_noargs
management.call_command('migrate', **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 149, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/venv/local/lib/python2.7/site-packages/south/migration/__init__.py", line 171, in migrate_app
south.db.db = south.db.dbs[database]
KeyError: 'secondary'
When rebuilding my indices via ./manage.py rebuild_index I get this error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/rebuild_index.py", line 13, in handle
call_command('clear_index', **options)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/clear_index.py", line 38, in handle
sb.clear()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 197, in clear
self.setup()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 105, in setup
self.index = self.storage.open_index(schema=self.schema)
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/filestore.py", line 48, in open_index
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 94, in __init__
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 173, in _read
IndexError: Index was created on an architecture with different data sizes
You have probably downgraded from whoosh 1.0.0 to 0.3.18, but there are some buggy index files already created at the path you defined by HAYSTACK_WHOOSH_PATH. Just make that directory empty and try again.