From 6e3ac5f4743b75c3e3dd36560c92af15e5b72997 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 16 Jun 2014 10:28:31 -0700 Subject: [PATCH] Fixed #22847: Optimizer wasn't expecting unresolved FKs --- django/db/migrations/optimizer.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/django/db/migrations/optimizer.py b/django/db/migrations/optimizer.py index 8e285c8b76..52a822ebf7 100644 --- a/django/db/migrations/optimizer.py +++ b/django/db/migrations/optimizer.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django.db import migrations +from django.utils import six class MigrationOptimizer(object): @@ -205,10 +206,12 @@ class MigrationOptimizer(object): # Don't allow optimisations of FKs through models they reference if hasattr(other.field, "rel") and other.field.rel: for between in in_between: - if between.references_model( - other.field.rel.to._meta.object_name, - other.field.rel.to._meta.app_label, - ): + if isinstance(other.field.rel.to, six.string_types): + object_name, app_label = other.field.rel.to.split(".", 1) + else: + object_name = other.field.rel.to._meta.object_name + app_label = other.field.rel.to._meta.app_label + if between.references_model(object_name, app_label): return None # OK, that's fine return [