I have a problem with Django quite incomprehensible.
I used models.py to model my database. This database runs on the production server. I want to change it, so I create a new database on the development server. The problem happens when I do syncdb, Django tries to create twice the same table, as you can see below:
python manage.py syncdb
Operations to perform:
Synchronize unmigrated apps: inventaryApp, newPrpvApp, grappelli, debug_toolbar, registration, import_export
Apply all migrations: sitetree, sessions, admin, sites, auth, contenttypes
Synchronizing apps without migrations:
Creating tables...
Creating table u_institutions
Creating table u_users
Creating table o_organes
Creating table o_degats
Creating table o_validation
Creating table o_m_determination
Creating table o_stades_dvlpmt
Creating table o_types
Creating table precision_date
Creating table t_categories
Creating table t_etat_synonymie
Creating table g_langues
Creating table g_pays
Creating table g_regions
Creating table g_communes
Creating table pays_langues
Creating table newprpvapp_userprofile
Creating table t_noms_verna
Creating table langues_noms_verna
Creating table maladies
Creating table t_familles
Creating table t_genres
Creating table t_especes
Creating table images
Creating table esp_noms_verna
Creating table t_infra_types
Creating table t_infra_sp
Creating table t_synonymes
Creating table o_contexte
Creating table o_interception
Creating table o_hotes
Creating table hotes_organes
Creating table o_organismes_associes
Creating table u_institutions
As you can see, the u_institutions table is created the first, but also at the end. And this is where the execution of the command stops to show:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 27, in handle_noargs
call_command("migrate", **options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 239, in sync_apps
cursor.execute(statement)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "u_institutions" already exists
I have verified that the table had not been set twice in model.py, and it was not. I use Django 1.7, and psycopg 2.6. Do you have an idea please? Thank you all!
Edit
I had already executed makemigrations, and everything was good. Now it indicates that no change is detected, which is probably normal.
When I try migrate, I get :
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 239, in sync_apps
cursor.execute(statement)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "u_institutions" already exists
And migrate --fake return :
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 239, in sync_apps
cursor.execute(statement)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/hugo/DEV/.virtualenvs/env_eprpv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "u_institutions" already exists
It seems that you have already created your database schema. Please, use migration (as long as you use Django 1.7). syncdb is deprecated.
python manage.py makemigrations
python manage.py migrate
If you will face any errors here (like relation "..." already exists) run this command to mark this tables as applied:
python manage.py migrate --fake
Related
I am trying to unitest my models in my django application that consisits of some migrations. I have prepared my test, but when running
./manage.py test my_app
i get the following error
django.db.utils.OperationalError: (1005, "Can't create table 'test_rhombusdb.#sql-4ca_2c' (errno: 150)")
The database is created normally, So I guess I have permissions to create the db.
I really don't know which table this is reffering to. Migrations pass normal and db works fine in production. What could be the issue here?
what other info would you like?
my stack trace
File "./manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1005, "Can't create table 'testdb.#sql-4ca_7c' (errno: 150)")
I can see there is an error when migration is called.
PS: I droped my database(real one but the developement one) and tried to recreate tables running migrate. I came with the same error. Running migrate again worked like a charm....Something is really really really wrong here....
PS2: Deleting all migration folders and starting without gave me the same error after running migrate with no migration folders present....Very bad error very difficult to debug
PS3: There is an issue with the foreign key on one (at least so far i've tested) of my models. I tried deactivating apps and activating them in terms, and when I got to a specific one, error occured.I isolated one model, and gave me the issue. I commented out the foreign keys and worked. Uncomment one of them error again.
class Patient(models.Model):
#many fields here
doctor = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="patients")
It worked with 1.6 and sqlite3, I moved to 1.8 and mysql, and boom...error.
AUTH_USER_MODEL = 'users.MyCustomUser'
MyCustomUser is a class inheriting AbstractBaseUser and PermissionsMixin.
I had the same (pretty general) error message. For me it came down to having forgot to run makemigrations on a new app. See also:
https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies
I keep getting an error with my redshift database, I can't seem to run a ./manage.py inspectdb command on the database.
I did a select * from pg_user, and verified my user was a superuser.
Still not sure why this problem exists, https://forums.aws.amazon.com/thread.jspa?threadID=133514 this is an old link to the problem.
Error:
django.db.utils.ProgrammingError: must be superuser to examine "max_index_keys"
CONTEXT: SQL function "_pg_keypositions" statement 1
The error log:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/commands/inspectdb.py", line 25, in handle
for line in self.handle_inspection(options):
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/core/mana gement/commands/inspectdb.py", line 72, in handle_inspection
constraints = connection.introspection.get_constraints(cursor, table_name)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/db/backen ds/postgresql_psycopg2/introspection.py", line 187, in get_constraints
""", ["public", table_name])
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/db/backen ds/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/db/backen ds/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/db/utils. py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/webapps/hello_django/local/lib/python2.7/site-packages/django/db/backen ds/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be superuser to examine "max_index_keys"
CONTEXT: SQL function "_pg_keypositions" statement 1
I use django_celery with connecting to Amazon Redshift. To migrate database, after "makemigrations" I used command "python manage.py migrate" and error message show up as shown below.
The reason is Redshift does not support data type 'serial' but the 'django_migrations' table that contain 'serial' type is automatically created.
How to stop Django Migrations create this table or avoid using serial on 'django_migrations' table.
D:\code\test_celery_django>python manage.py migrate
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 338, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 180, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema
editor.create_model(self.Migration)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 286, in create_model
self.execute(sql, params or None)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 111, in execute
cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.NotSupportedError: Column "django_migrations.id" has unsupported type "serial".
Are you trying to use Redshift as the backend database for your web application? That's a bad idea, Redshift is a data warehouse and as such individual query performance and latency are far from great, not to mention that Redshift doesn't enforce primary keys, which almost surely Django expects.
My recommendation, use PostgreSQL.
Im trying to write simple application with this project structure:
website (root directory)
..mainws (its app)
....migrations(not filled)
....usermodels
......__init__.py
......Role.py
....__init__.py
....admin.py
....models.py
....test.py
....views.py
..website(directory for project)
..manage.py
And after making project, I created mainws app, when wrote for Role table. Also added in models.py (directory mainws):
from usermodels import Role
But using in terminal "manage.py sqlall mainws" giving for me big stacktrace (mainws app added at the and of INSTALLED_APPS). How can I fix this trouble?
Role.py contains code:
from django.db import models
class Role(models.Model):
role_name = models.CharField(max_length=25)
def GetRoleName(self):
return self.role_name
def SetRoleName(self, new_role_name):
if self.role_name != new_role_name:
self.role_name = new_role_name
Stacktrace:
=> python manage.py sqlall mainws
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/base.py", line 449, in handle
app_output = self.handle_app_config(app_config, **options)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/commands/sqlall.py", line 25, in handle_app_config
statements = sql_all(app_config, self.style, connection)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/sql.py", line 174, in sql_all
check_for_migrations(app_config, connection)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/core/management/sql.py", line 18, in check_for_migrations
loader = MigrationLoader(connection)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/migrations/loader.py", line 179, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 53, in ensure_schema
editor.create_model(self.Migration)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/backends/schema.py", line 263, in create_model
self.execute(sql, params)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/backends/schema.py", line 99, in execute
cursor.execute(sql, params)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/savicvalera/code/lab8/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: no schema has been selected to create in
Do the following changes :
1) Rename your usermodels folder to models folder(for simplicity).
2) In the __init__.py file of models folder, import the Role model using from . import Role.
3) leave the models.py file(of the outer directory) blank.
So ultimately you will have the following structure
website (root directory)
..mainws (its app)
....migrations(not filled)
....models
......__init__.py
......Role.py
....__init__.py
....admin.py
....models.py
....test.py
....views.py
..website(directory for project)
..manage.py
Then run the sqlall command.It should work!
When I issue the command:
python manage.py syncdb --database=mydb
It shows the output as follows...
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
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 459, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/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 "/usr/lib/python2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 35, in create_permissions
ctype = ContentType.objects.get_for_model(klass)
File "/usr/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 42, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 134, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 442, in get_or_create
return self.get(**lookup), False
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 361, in get
num = len(clone)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 85, in __len__
self._result_cache = list(self.iterator())
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
for row in compiler.results_iter():
File "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: django_content_type
I have a custom db router that is basically set to django's example, except i have a custom attribute on MY models so that it knows which database they default to. syncdb works when in my settings.py INSTALLED_APPS I comment out: django.contrib.auth and django.contrib.contenttypes. Had this problem for a while, but have been putting it off until now, when I need to start on authentication. If you want my db router I'll post also
I've explained a similar problem here:
django.db.utils.IntegrityError: (1062, "Duplicate entry '22-add_' for key 'content_type_id'")
You don't need to comment out contrib.auth and contrib.contenttypes. Just make sure all django models - users, sessions, permissions are only used in 1 database, which could be considered as a master.
This will not directly solve your problem, but can be a starting point when dealing with multiple db's and db routers. What you need to know is that each model has it's content type in the database.
The problem occur when django objects - user/session/permission are not restricted to a single database - then they are created into each database. And since a content-type makes a model unique, having content-types for a single type in multiple databases could lead to the problem explained in the other SO question above.
In Django 1.4 you have to launch this command in the top-level folder of the project (path_to_project/you_project NOT path_to_project/you_project/you_project)