Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1928 -- Correctly create foreign key references when there are…

… multiple

keys on multiple models. Based on a patch from Geert Vanderkelen and some
diagnosis from hornero.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3182 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ba22f55aa2766cb6a0b58c0e1be6164a48adcb02 1 parent 0e92f70
Malcolm Tredinnick authored June 21, 2006

Showing 1 changed file with 10 additions and 2 deletions. Show diff stats Hide diff stats

  1. 12  django/core/management.py
12  django/core/management.py
@@ -106,7 +106,11 @@ def get_sql_create(app):
106 106
     for klass in app_models:
107 107
         output, references = _get_sql_model_create(klass, models_output)
108 108
         final_output.extend(output)
109  
-        pending_references.update(references)
  109
+        for refto, refs in references.items():
  110
+            try:
  111
+                pending_references[refto].extend(refs)
  112
+            except KeyError:
  113
+                pending_references[refto] = refs
110 114
         final_output.extend(_get_sql_for_pending_references(klass, pending_references))
111 115
         # Keep track of the fact that we've created the table for this model.
112 116
         models_output.add(klass)
@@ -458,7 +462,11 @@ def syncdb():
458 462
             sql, references = _get_sql_model_create(model, seen_models)
459 463
             seen_models.add(model)
460 464
             created_models.add(model)
461  
-            pending_references.update(references)
  465
+            for refto, refs in references.items():
  466
+                try:
  467
+                    pending_references[refto].extend(refs)
  468
+                except KeyError:
  469
+                    pending_references[refto] = refs
462 470
             sql.extend(_get_sql_for_pending_references(model, pending_references))
463 471
             print "Creating table %s" % model._meta.db_table
464 472
             for statement in sql:

0 notes on commit ba22f55

Please sign in to comment.
Something went wrong with that request. Please try again.