diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index a9daf1c..33bd44d 100644
a
|
b
|
from django.core.management.color import no_style
|
8 | 8 | from django.db import DEFAULT_DB_ALIAS, connections, router |
9 | 9 | |
10 | 10 | |
11 | | def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs): |
| 11 | def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs): |
12 | 12 | try: |
13 | 13 | Site = apps.get_model('sites', 'Site') |
14 | 14 | except LookupError: |
15 | 15 | return |
16 | 16 | |
17 | | if not router.allow_migrate(db, Site): |
| 17 | if not router.allow_migrate(using, Site): |
18 | 18 | return |
19 | 19 | |
20 | 20 | if not Site.objects.exists(): |
… |
… |
def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
|
25 | 25 | # can also crop up outside of tests - see #15346. |
26 | 26 | if verbosity >= 2: |
27 | 27 | print("Creating example.com Site object") |
28 | | Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=db) |
| 28 | Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=using) |
29 | 29 | |
30 | 30 | # We set an explicit pk instead of relying on auto-incrementation, |
31 | 31 | # so we need to reset the database sequence. See #17415. |
32 | | sequence_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site]) |
| 32 | sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site]) |
33 | 33 | if sequence_sql: |
34 | 34 | if verbosity >= 2: |
35 | 35 | print("Resetting sequence") |
36 | | with connections[db].cursor() as cursor: |
| 36 | with connections[using].cursor() as cursor: |
37 | 37 | for command in sequence_sql: |
38 | 38 | cursor.execute(command) |
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 72c7a9f..c820b02 100644
a
|
b
|
class CreateDefaultSiteTests(TestCase):
|
151 | 151 | """ |
152 | 152 | #16353, #16828 - The default site creation should respect db routing. |
153 | 153 | """ |
154 | | create_default_site(self.app_config, db='default', verbosity=0) |
155 | | create_default_site(self.app_config, db='other', verbosity=0) |
| 154 | create_default_site(self.app_config, using='default', verbosity=0) |
| 155 | create_default_site(self.app_config, using='other', verbosity=0) |
156 | 156 | self.assertFalse(Site.objects.using('default').exists()) |
157 | 157 | self.assertTrue(Site.objects.using('other').exists()) |
158 | 158 | |