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:
parent
0e92f70602
commit
ba22f55aa2
|
@ -106,7 +106,11 @@ def get_sql_create(app):
|
||||||
for klass in app_models:
|
for klass in app_models:
|
||||||
output, references = _get_sql_model_create(klass, models_output)
|
output, references = _get_sql_model_create(klass, models_output)
|
||||||
final_output.extend(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))
|
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.
|
# Keep track of the fact that we've created the table for this model.
|
||||||
models_output.add(klass)
|
models_output.add(klass)
|
||||||
|
@ -458,7 +462,11 @@ def syncdb():
|
||||||
sql, references = _get_sql_model_create(model, seen_models)
|
sql, references = _get_sql_model_create(model, seen_models)
|
||||||
seen_models.add(model)
|
seen_models.add(model)
|
||||||
created_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))
|
sql.extend(_get_sql_for_pending_references(model, pending_references))
|
||||||
print "Creating table %s" % model._meta.db_table
|
print "Creating table %s" % model._meta.db_table
|
||||||
for statement in sql:
|
for statement in sql:
|
||||||
|
|
Loading…
Reference in New Issue