From 50bf56767531e1f29e000d039237ad1149d46bad Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 10 Mar 2008 22:18:50 +0000 Subject: [PATCH] Fixed #6374: cross-app and circular FK constraints are now detected and added correctly. Thanks, dready. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7215 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/core/management/commands/syncdb.py | 2 ++ django/core/management/sql.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index 9c28d73730..19c740a5cf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -112,6 +112,7 @@ answer newbie questions, and generally made Django that much better: Sander Dijkhuis Jordan Dimov dne@mayonnaise.net + dready Maximillian Dornseif Jeremy Dunck Andrew Durdin diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py index 0f21130f7a..8017ed832f 100644 --- a/django/core/management/commands/syncdb.py +++ b/django/core/management/commands/syncdb.py @@ -67,6 +67,8 @@ class Command(NoArgsCommand): created_models.add(model) for refto, refs in references.items(): pending_references.setdefault(refto, []).extend(refs) + if refto in seen_models: + sql.extend(sql_for_pending_references(refto, self.style, pending_references)) sql.extend(sql_for_pending_references(model, self.style, pending_references)) if verbosity >= 1: print "Creating table %s" % model._meta.db_table diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 15bffce26b..ab3a7b64c5 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -90,6 +90,8 @@ def sql_create(app, style): final_output.extend(output) for refto, refs in references.items(): pending_references.setdefault(refto, []).extend(refs) + if refto in known_models: + final_output.extend(sql_for_pending_references(refto, style, pending_references)) final_output.extend(sql_for_pending_references(model, style, pending_references)) # Keep track of the fact that we've created the table for this model. known_models.add(model)