[1.7.x] Fixed #22847: Optimizer wasn't expecting unresolved FKs
This commit is contained in:
parent
d9a7663b11
commit
02860e779c
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class MigrationOptimizer(object):
|
class MigrationOptimizer(object):
|
||||||
|
@ -205,10 +206,12 @@ class MigrationOptimizer(object):
|
||||||
# Don't allow optimisations of FKs through models they reference
|
# Don't allow optimisations of FKs through models they reference
|
||||||
if hasattr(other.field, "rel") and other.field.rel:
|
if hasattr(other.field, "rel") and other.field.rel:
|
||||||
for between in in_between:
|
for between in in_between:
|
||||||
if between.references_model(
|
if isinstance(other.field.rel.to, six.string_types):
|
||||||
other.field.rel.to._meta.object_name,
|
object_name, app_label = other.field.rel.to.split(".", 1)
|
||||||
other.field.rel.to._meta.app_label,
|
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
|
return None
|
||||||
# OK, that's fine
|
# OK, that's fine
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue