summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2011-08-07 00:43:26 +0000
committerKaren Tracey <kmtracey@gmail.com>2011-08-07 00:43:26 +0000
commitbe87f0b0ec992e6f3e72735d8e95c654da969f6d (patch)
treefa4d16b640e716dcd8271f2e6a7e3bb2953cbe5d /django/core
parente3c89346d217fca92b62a6d11df6b4b6d5be28a2 (diff)
Fixed #3615: Added support for loading fixtures with forward references on database backends (such as MySQL/InnoDB) that do not support deferred constraint checking. Many thanks to jsdalton for coming up with a clever solution to this long-standing issue, and to jacob, ramiro, graham_king, and russellm for review/testing. (Apologies if I missed anyone else who helped here.)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16590 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/commands/loaddata.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index 34f354341e..952b1cb20a 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -1,3 +1,7 @@
+# This is necessary in Python 2.5 to enable the with statement, in 2.6
+# and up it is no longer necessary.
+from __future__ import with_statement
+
import sys
import os
import gzip
@@ -166,12 +170,20 @@ class Command(BaseCommand):
(format, fixture_name, humanize(fixture_dir)))
try:
objects = serializers.deserialize(format, fixture, using=using)
- for obj in objects:
- objects_in_fixture += 1
- if router.allow_syncdb(using, obj.object.__class__):
- loaded_objects_in_fixture += 1
- models.add(obj.object.__class__)
- obj.save(using=using)
+
+ with connection.constraint_checks_disabled():
+ for obj in objects:
+ objects_in_fixture += 1
+ if router.allow_syncdb(using, obj.object.__class__):
+ loaded_objects_in_fixture += 1
+ models.add(obj.object.__class__)
+ obj.save(using=using)
+
+ # Since we disabled constraint checks, we must manually check for
+ # any invalid keys that might have been added
+ table_names = [model._meta.db_table for model in models]
+ connection.check_constraints(table_names=table_names)
+
loaded_object_count += loaded_objects_in_fixture
fixture_object_count += objects_in_fixture
label_found = True