Code

Ticket #16353: sites-and-multi-db.diff

File sites-and-multi-db.diff, 1.3 KB (added by aaugustin, 3 years ago)
Line 
1Index: django/db/backends/creation.py
2===================================================================
3--- django/db/backends/creation.py      (revision 16467)
4+++ django/db/backends/creation.py      (working copy)
5@@ -252,8 +252,11 @@
6         # default site may or may not be 1, depending on how the sequence was
7         # reset.  If the sites app is loaded, then we coerce it.
8         from django.db.models import get_model
9+        from django.db import router
10         Site = get_model('sites', 'Site')
11-        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
12+        if (Site is not None
13+            and router.allow_syncdb(self.connection.alias, Site)
14+            and Site.objects.using(self.connection.alias).count() == 1):
15             Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
16 
17         from django.core.cache import get_cache
18@@ -261,7 +264,6 @@
19         for cache_alias in settings.CACHES:
20             cache = get_cache(cache_alias)
21             if isinstance(cache, BaseDatabaseCache):
22-                from django.db import router
23                 if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
24                     call_command('createcachetable', cache._table, database=self.connection.alias)
25