Index: django/core/management/sql.py
===================================================================
--- django/core/management/sql.py	(revision 7041)
+++ django/core/management/sql.py	(working copy)
@@ -90,7 +90,7 @@
         final_output.extend(output)
         for refto, refs in references.items():
             pending_references.setdefault(refto, []).extend(refs)
-        final_output.extend(sql_for_pending_references(model, style, pending_references))
+        final_output.extend(sql_for_pending_references(model, style, pending_references, known_models))
         # Keep track of the fact that we've created the table for this model.
         known_models.add(model)
 
@@ -314,7 +314,7 @@
 
     return final_output, pending_references
 
-def sql_for_pending_references(model, style, pending_references):
+def sql_for_pending_references(model, style, pending_references, known_models=[]):
     """
     Returns any ALTER TABLE statements to add constraints after the fact.
     """
@@ -324,21 +324,29 @@
     qn = connection.ops.quote_name
     final_output = []
     if connection.features.supports_constraints:
-        opts = model._meta
+        for src_class in pending_references:
+            opts = src_class._meta
+            rels = pending_references[src_class]
+            i = 0
+            while i < len(rels):
+                rel_class, f = rels[i]
+                if src_class == model or (known_models and rel_class == model and (src_class in known_models)):
+                    rel_opts = rel_class._meta
+                    r_table = rel_opts.db_table
+                    r_col = f.column
+                    table = opts.db_table
+                    col = opts.get_field(f.rel.field_name).column
+                    # For MySQL, r_name must be unique in the first 64 characters.
+                    # So we are careful with character usage here.
+                    r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
+                    final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
+                        (qn(r_table), truncate_name(r_name, connection.ops.max_name_length()),
+                        qn(r_col), qn(table), qn(col),
+                        connection.ops.deferrable_sql()))
+                    del rels[i]
+                else:
+                    i = i + 1
         if model in pending_references:
-            for rel_class, f in pending_references[model]:
-                rel_opts = rel_class._meta
-                r_table = rel_opts.db_table
-                r_col = f.column
-                table = opts.db_table
-                col = opts.get_field(f.rel.field_name).column
-                # For MySQL, r_name must be unique in the first 64 characters.
-                # So we are careful with character usage here.
-                r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
-                final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
-                    (qn(r_table), truncate_name(r_name, connection.ops.max_name_length()),
-                    qn(r_col), qn(table), qn(col),
-                    connection.ops.deferrable_sql()))
             del pending_references[model]
     return final_output
 
