From fb30e774f91fb91372b0a5a3e707fbbd1996da83 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 27 Apr 2007 12:45:08 +0000 Subject: [PATCH] Fixed #2608 -- Generate correct SQL for multi-level foreign key relations. Based on a patch from Gopal Narayanan. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5106 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/core/management.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 52811b9445..60baa3f831 100644 --- a/AUTHORS +++ b/AUTHORS @@ -164,6 +164,7 @@ answer newbie questions, and generally made Django that much better: Robin Munn Robert Myers Nebojša Dorđević + Gopal Narayanan Fraser Nevett Sam Newman Neal Norwitz diff --git a/django/core/management.py b/django/core/management.py index d2f0d1e837..4e6a5f45b3 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -168,6 +168,8 @@ def _get_sql_model_create(model, known_models=set()): for f in opts.fields: if isinstance(f, (models.ForeignKey, models.OneToOneField)): rel_field = f.rel.get_related_field() + while isinstance(rel_field, (models.ForeignKey, models.OneToOneField)): + rel_field = rel_field.rel.get_related_field() data_type = get_rel_data_type(rel_field) else: rel_field = f