Uniform content type tables with multiple databases

127 views
Skip to first unread message

Mario Taddei

unread,
Nov 2, 2016, 12:09:15 PM11/2/16
to Django developers (Contributions to Django itself)
Hi all, 
I noticed that with multiple databases, the content_type tables are not filled in the same way. It is not a bug, but having uniform content type tables through multiple databases makes life easier.

If 'django.contrib.contenttypes' app comes before 'django.contrib.auth' in INSTALLED_APPS
the content_type table is filled here: https://github.com/django/django/blob/1.8.9/django/contrib/contenttypes/management.py#L53 

else (only in the database where 'auth' is migrated, previous method for the other databases)
it is filled by the method get_for_model() 
https://github.com/django/django/blob/1.8.9/django/contrib/contenttypes/models.py#L69
called in the 'django.contrib.auth' signal handler: https://github.com/django/django/blob/1.8.9/django/contrib/auth/management/__init__.py#L82


For the moment I adopted this solution (don't know if it is the best): 
'contenttypes' before 'auth' in INSTALLED_APPS
and this little modif using sorted() method: https://github.com/mariuccio/django/blob/stable/1.8.x/django/contrib/contenttypes/management.py#L50


Thanks for any advice,
Mario

Tim Graham

unread,
Nov 8, 2016, 12:14:50 PM11/8/16
to Django developers (Contributions to Django itself)
I'm not sure if anything could or should be done, but I noticed a warning in the documentation that Aymeric added:

"If you’re synchronizing content types to more than one database, be aware that their primary keys may not match across databases. This may result in data corruption or data loss."

https://github.com/django/django/commit/a026e480d
Reply all
Reply to author
Forward
0 new messages