Django `auth` and` contenttypes` break syncdb

When I issue the command:

python manage.py syncdb --database=mydb

It shows the result 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 mostly configured with a django example, except that I have a custom attribute on MY models so that it knows which database they are by default to. syncdb works when in my settings.py INSTALLED_APPS I comment: django.contrib.auth and django.contrib.contenttypes . This problem occurred for a while, but it has been putting it off until now when I need to start authentication. If you want my db router, I will also post

+4
source share
2 answers

I explained a similar problem: django.db.utils.IntegrityError: (1062, "Duplicate entry" 22 -add_ "for key" content_type_id ", etc.)

You do not need to comment on the contrib.auth and contrib.contenttypes tabs. Just make sure that all django models - users, sessions, permissions are used in only 1 database, which can be considered a wizard.

This will not solve your problem directly, but it can be a starting point when working with multiple db and db routers. What you need to know is that each model has a content type in the database. The problem occurs when django objects - user / session / permission are not limited to one database - then they are created in each database. And since the content type makes the model unique, having content types for the same type in multiple databases can lead to the problem described in another SO question above.

+3
source

In Django 1.4, you need to run this command in the top-level folder of the project (path_to_project / you_project NOT path_to_project / you_project / you_project)

0
source

All Articles