diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py index 975bafe1ff..a9daf1cc75 100644 --- a/django/contrib/sites/management.py +++ b/django/contrib/sites/management.py @@ -3,6 +3,7 @@ Creates the default Site object. """ from django.apps import apps +from django.conf import settings from django.core.management.color import no_style from django.db import DEFAULT_DB_ALIAS, connections, router @@ -24,7 +25,7 @@ def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB # can also crop up outside of tests - see #15346. if verbosity >= 2: print("Creating example.com Site object") - Site(pk=1, domain="example.com", name="example.com").save(using=db) + Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=db) # We set an explicit pk instead of relying on auto-incrementation, # so we need to reset the database sequence. See #17415. diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py index 5b6b1fc4a8..72c7a9f8c7 100644 --- a/django/contrib/sites/tests.py +++ b/django/contrib/sites/tests.py @@ -176,6 +176,14 @@ class CreateDefaultSiteTests(TestCase): post_migrate.send(sender=self.app_config, app_config=self.app_config, verbosity=0) self.assertTrue(Site.objects.exists()) + @override_settings(SITE_ID=35696) + def test_custom_site_id(self): + """ + #23945 - The configured ``SITE_ID`` should be respected. + """ + create_default_site(self.app_config, verbosity=0) + self.assertEqual(Site.objects.get().pk, 35696) + class MiddlewareTest(TestCase): diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index f96067fa81..4afa02dd18 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -168,6 +168,10 @@ Minor features ` if the :setting:`SITE_ID` setting is not defined. +* The default :class:`~django.contrib.sites.models.Site` created when running + ``migrate`` now respects the :setting:`SITE_ID` setting (instead of always + using ``pk=1``). + :mod:`django.contrib.staticfiles` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^