﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6374	Foreign key constraints not added across apps when creating tables	Wil Tan	Jacob	"I have an app that has foreign keys to django.contrib.auth.models.User but when doing 'syncdb' or 'sql', it doesn't define the foreign keys. My database engine is MySQL and I'm using SVN rev 7020.

I think this patch might work, but I'm in no way familiar with Django internals:


{{{

Index: django/core/management/sql.py
===================================================================
--- django/core/management/sql.py       (revision 7020)
+++ django/core/management/sql.py       (working copy)
@@ -90,6 +90,8 @@
         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)
}}}

"		closed	Database layer (models, ORM)	dev		fixed	mysql db models		Unreviewed	1	0	0	0	0	0
