1
0
mirror of https://github.com/django/django.git synced 2025-04-17 22:04:38 +00:00

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

Backport of e8cf4f8abec87b9da6ed8e5c8cf833af9b27f4dd from master
This commit is contained in:
Tim Graham 2015-02-12 13:58:37 -05:00
parent 5697a4c9cf
commit 1b93b0977d
3 changed files with 12 additions and 2 deletions
django/contrib/sites
docs/releases

@ -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

@ -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.

@ -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`).