mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user