Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 malcolmt authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 django/core/management.py
12 django/core/management.py
View
@@ -106,7 +106,11 @@ def get_sql_create(app):
for klass in app_models:
output, references = _get_sql_model_create(klass, models_output)
final_output.extend(output)
- pending_references.update(references)
+ for refto, refs in references.items():
+ try:
+ pending_references[refto].extend(refs)
+ except KeyError:
+ pending_references[refto] = refs
final_output.extend(_get_sql_for_pending_references(klass, pending_references))
# Keep track of the fact that we've created the table for this model.
models_output.add(klass)
@@ -458,7 +462,11 @@ def syncdb():
sql, references = _get_sql_model_create(model, seen_models)
seen_models.add(model)
created_models.add(model)
- pending_references.update(references)
+ for refto, refs in references.items():
+ try:
+ pending_references[refto].extend(refs)
+ except KeyError:
+ pending_references[refto] = refs
sql.extend(_get_sql_for_pending_references(model, pending_references))
print "Creating table %s" % model._meta.db_table
for statement in sql:
Please sign in to comment.
Something went wrong with that request. Please try again.