diff -r 289df89a57e4 django/core/management/commands/loaddata.py
--- a/django/core/management/commands/loaddata.py	Fri Jan 09 10:41:07 2009 -0200
+++ b/django/core/management/commands/loaddata.py	Sat Jan 10 12:19:16 2009 -0200
@@ -27,6 +27,10 @@
         from django.core import serializers
         from django.db import connection, transaction
         from django.conf import settings
+
+        def enable_constraint_checks():
+            if not connection.features.can_defer_constraint_checks:
+                connection.enable_forward_ref_checks()
 
         self.style = no_style()
 
@@ -59,6 +63,9 @@
             transaction.commit_unless_managed()
             transaction.enter_transaction_management()
             transaction.managed(True)
+
+        if not connection.features.can_defer_constraint_checks:
+            connection.disable_forward_ref_checks()
 
         class SingleZipReader(zipfile.ZipFile):
             def __init__(self, *args, **kwargs):
@@ -100,6 +107,7 @@
                 if verbosity > 1:
                     print "Loading '%s' fixtures..." % fixture_name
             else:
+                enable_constraint_checks()
                 sys.stderr.write(
                     self.style.ERROR("Problem installing fixture '%s': %s is not a known serialization format." %
                         (fixture_name, format)))
@@ -119,21 +127,22 @@
                 label_found = False
                 for format in formats:
                     for compression_format in compression_formats:
-                        if compression_format: 
-                            file_name = '.'.join([fixture_name, format, 
+                        if compression_format:
+                            file_name = '.'.join([fixture_name, format,
                                                   compression_format])
-                        else: 
+                        else:
                             file_name = '.'.join([fixture_name, format])
-                    
+
                         if verbosity > 1:
                             print "Trying %s for %s fixture '%s'..." % \
                                 (humanize(fixture_dir), file_name, fixture_name)
                         full_path = os.path.join(fixture_dir, file_name)
-                        open_method = compression_types[compression_format]                                
-                        try: 
+                        open_method = compression_types[compression_format]
+                        try:
                             fixture = open_method(full_path, 'r')
                             if label_found:
                                 fixture.close()
+                                enable_constraint_checks()
                                 print self.style.ERROR("Multiple fixtures named '%s' in %s. Aborting." %
                                     (fixture_name, humanize(fixture_dir)))
                                 transaction.rollback()
@@ -154,14 +163,15 @@
                                     object_count += objects_in_fixture
                                     label_found = True
                                 except (SystemExit, KeyboardInterrupt):
+                                    enable_constraint_checks()
                                     raise
                                 except Exception:
                                     import traceback
                                     fixture.close()
+                                    enable_constraint_checks()
                                     transaction.rollback()
                                     transaction.leave_transaction_management()
                                     if show_traceback:
-                                        import traceback
                                         traceback.print_exc()
                                     else:
                                         sys.stderr.write(
@@ -173,6 +183,7 @@
                                 # If the fixture we loaded contains 0 objects, assume that an
                                 # error was encountered during fixture loading.
                                 if objects_in_fixture == 0:
+                                    enable_constraint_checks()
                                     sys.stderr.write(
                                         self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" %
                                             (fixture_name)))
@@ -184,6 +195,8 @@
                             if verbosity > 1:
                                 print "No %s fixture '%s' in %s." % \
                                     (format, fixture_name, humanize(fixture_dir))
+
+        enable_constraint_checks()
 
         # If we found even one object in a fixture, we need to reset the
         # database sequences.
diff -r 289df89a57e4 django/db/backends/__init__.py
--- a/django/db/backends/__init__.py	Fri Jan 09 10:41:07 2009 -0200
+++ b/django/db/backends/__init__.py	Sat Jan 10 12:19:16 2009 -0200
@@ -61,6 +61,12 @@
     def make_debug_cursor(self, cursor):
         return util.CursorDebugWrapper(cursor, self)
 
+    def disable_forward_ref_checks(self):
+        pass
+
+    def enable_forward_ref_checks(self):
+        pass
+
 class BaseDatabaseFeatures(object):
     # True if django.db.backend.utils.typecast_timestamp is used on values
     # returned from dates() calls.
@@ -74,6 +80,7 @@
     # If True, don't use integer foreign keys referring to, e.g., positive
     # integer primary keys.
     related_fields_match_type = False
+    can_defer_constraint_checks = True
 
 class BaseDatabaseOperations(object):
     """
diff -r 289df89a57e4 django/db/backends/mysql/base.py
--- a/django/db/backends/mysql/base.py	Fri Jan 09 10:41:07 2009 -0200
+++ b/django/db/backends/mysql/base.py	Sat Jan 10 12:19:16 2009 -0200
@@ -111,6 +111,7 @@
     empty_fetchmany_value = ()
     update_can_self_select = False
     related_fields_match_type = True
+    can_defer_constraint_checks = False
 
 class DatabaseOperations(BaseDatabaseOperations):
     def date_extract_sql(self, lookup_type, field_name):
@@ -288,3 +289,9 @@
                 raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
             self.server_version = tuple([int(x) for x in m.groups()])
         return self.server_version
+
+    def disable_forward_ref_checks(self):
+        self.cursor().execute('SET FOREIGN_KEY_CHECKS=0;')
+
+    def enable_forward_ref_checks(self):
+        self.cursor().execute('SET FOREIGN_KEY_CHECKS=1;')
diff -r 289df89a57e4 tests/modeltests/fixtures/fixtures/forward_references.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modeltests/fixtures/fixtures/forward_references.json	Sat Jan 10 12:19:16 2009 -0200
@@ -0,0 +1,180 @@
+[
+    {
+        "pk": 1,
+        "model": "fixtures.store",
+        "fields": {
+            "book": 1,
+            "name": "Amazon.com"
+        }
+    },
+    {
+        "pk": 2,
+        "model": "fixtures.store",
+        "fields": {
+            "book": 3,
+            "name": "Books.com"
+        }
+    },
+    {
+        "pk": 3,
+        "model": "fixtures.store",
+        "fields": {
+            "book": 4,
+            "name": "Mamma and Pappa's Books"
+        }
+    },
+    {
+        "pk": 1,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 1,
+            "name": "The Definitive Guide to Django: Web Development Done Right",
+            "authors": [1, 2]
+        }
+    },
+    {
+        "pk": 2,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 2,
+            "name": "Sams Teach Yourself Django in 24 Hours",
+            "authors": [3]
+        }
+    },
+    {
+        "pk": 3,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 1,
+            "name": "Practical Django Projects",
+            "authors": [4]
+        }
+    },
+    {
+        "pk": 4,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 3,
+            "name": "Python Web Development with Django",
+            "authors": [5, 6, 7]
+        }
+    },
+    {
+        "pk": 5,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 3,
+            "name": "Artificial Intelligence: A Modern Approach",
+            "authors": [8, 9]
+        }
+    },
+    {
+        "pk": 6,
+        "model": "fixtures.book",
+        "fields": {
+            "publisher": 4,
+            "name": "Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp",
+            "authors": [8]
+        }
+    },
+    {
+        "pk": 1,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [2, 4],
+            "name": "Adrian Holovaty"
+        }
+    },
+    {
+        "pk": 2,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [1, 7],
+            "name": "Jacob Kaplan-Moss"
+        }
+    },
+    {
+        "pk": 3,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [],
+            "name": "Brad Dayley"
+        }
+    },
+    {
+        "pk": 4,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [1],
+            "name": "James Bennett"
+        }
+    },
+    {
+        "pk": 5,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [6, 7],
+            "name": "Jeffrey Forcier"
+        }
+    },
+    {
+        "pk": 6,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [5, 7],
+            "name": "Paul Bissex"
+        }
+    },
+    {
+        "pk": 7,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [2, 5, 6],
+            "name": "Wesley J. Chun"
+        }
+    },
+    {
+        "pk": 8,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [9],
+            "name": "Peter Norvig"
+        }
+    },
+    {
+        "pk": 9,
+        "model": "fixtures.author",
+        "fields": {
+            "friends": [8],
+            "name": "Stuart Russell"
+        }
+    },
+    {
+        "pk": 1,
+        "model": "fixtures.publisher",
+        "fields": {
+            "name": "Apress"
+        }
+    },
+    {
+        "pk": 2,
+        "model": "fixtures.publisher",
+        "fields": {
+            "name": "Sams"
+        }
+    },
+    {
+        "pk": 3,
+        "model": "fixtures.publisher",
+        "fields": {
+            "name": "Prentice Hall"
+        }
+    },
+    {
+        "pk": 4,
+        "model": "fixtures.publisher",
+        "fields": {
+            "name": "Morgan Kaufmann"
+        }
+    }
+]
diff -r 289df89a57e4 tests/modeltests/fixtures/models.py
--- a/tests/modeltests/fixtures/models.py	Fri Jan 09 10:41:07 2009 -0200
+++ b/tests/modeltests/fixtures/models.py	Sat Jan 10 12:19:16 2009 -0200
@@ -20,6 +20,34 @@
 
     class Meta:
         ordering = ('-pub_date', 'headline')
+
+class Author(models.Model):
+   name = models.CharField(max_length=100)
+   friends = models.ManyToManyField('self', blank=True)
+
+   def __unicode__(self):
+      return self.name
+
+class Publisher(models.Model):
+   name = models.CharField(max_length=300)
+
+   def __unicode__(self):
+      return self.name
+
+class Book(models.Model):
+   name = models.CharField(max_length=300)
+   authors = models.ManyToManyField(Author)
+   publisher = models.ForeignKey(Publisher)
+
+   def __unicode__(self):
+      return self.name
+
+class Store(models.Model):
+   name = models.CharField(max_length=300)
+   book = models.ForeignKey(Book)
+
+   def __unicode__(self):
+      return self.name
 
 __test__ = {'API_TESTS': """
 >>> from django.core import management
@@ -54,6 +82,15 @@
 # object list is unaffected
 >>> Article.objects.all()
 [<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>]
+
+# Reset the database representation of this app.
+# This will return the database to a clean initial state.
+>>> management.call_command('flush', verbosity=0, interactive=False)
+
+# Load a fixture that contains forward references in various forms
+>>> management.call_command('loaddata', 'forward_references', verbosity=0)
+>>> Author.objects.count()
+9
 """}
 
 # Database flushing does not work on MySQL with the default storage engine
