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
This commit is contained in:
Malcolm Tredinnick 2006-06-21 03:39:47 +00:00
parent 0e92f70602
commit ba22f55aa2
1 changed files with 10 additions and 2 deletions

View File

@ -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: