From 79bb9c145620ad6b4b424e2390c6e0b6905c122b Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Sat, 16 Apr 2011 18:43:01 +0000 Subject: [PATCH] [1.3.X] Fixed #15573: Forced the default site id to be 1 when creating test databases, to prevent a large number of errors when running the tests using the oracle backend. Backport of r16027 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16028 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/creation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index ef594b7bfc..75f07926c1 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -374,6 +374,14 @@ class BaseDatabaseCreation(object): verbosity=max(verbosity - 1, 0), interactive=False, database=self.connection.alias) + + # One effect of calling syncdb followed by flush is that the id of the + # default site may or may not be 1, depending on how the sequence was + # reset. If the sites app is loaded, then we coerce it. + from django.db.models import get_model + Site = get_model('sites', 'Site') + if Site is not None and Site.objects.using(self.connection.alias).count() == 1: + Site.objects.using(self.connection.alias).update(id=settings.SITE_ID) from django.core.cache import get_cache from django.core.cache.backends.db import BaseDatabaseCache