Commit 1b93b097 authored by Tim Graham's avatar Tim Graham
Browse files

[1.7.x] Fixed #24332 -- Fixed contrib.sites create_default_site() when...

[1.7.x] Fixed #24332 -- Fixed contrib.sites create_default_site() when 'default' DATABASES is empty.

Backport of e8cf4f8a from master
parent 5697a4c9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT
    if not router.allow_migrate(using, Site):
        return

    if not Site.objects.exists():
    if not Site.objects.using(using).exists():
        # The default settings set SITE_ID = 1, and some tests in Django's test
        # suite rely on this value. However, if database sequences are reused
        # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
+8 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class CreateDefaultSiteTests(TestCase):
        self.assertEqual(Site.objects.count(), 1)

    @unittest.skipIf('other' not in connections, "Requires 'other' database connection.")
    def test_multi_db(self):
    def test_multi_db_with_router(self):
        """
        #16353, #16828 - The default site creation should respect db routing.
        """
@@ -121,6 +121,13 @@ class CreateDefaultSiteTests(TestCase):
        finally:
            router.routers = old_routers

    @unittest.skipIf('other' not in connections, "Requires 'other' database connection.")
    def test_multi_db(self):
        create_default_site(self.app_config, using='default', verbosity=0)
        create_default_site(self.app_config, using='other', verbosity=0)
        self.assertTrue(Site.objects.using('default').exists())
        self.assertTrue(Site.objects.using('other').exists())

    def test_save_another(self):
        """
        #17415 - Another site can be created right after the default one.
+3 −0
Original line number Diff line number Diff line
@@ -16,3 +16,6 @@ Bugfixes

* Fixed a regression that prevented custom fields inheriting from
  ``ManyToManyField`` from being recognized in migrations (:ticket:`24236`).

* Fixed crash in ``contrib.sites`` migrations when a default database isn't
  used (:ticket:`24332`).