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)