summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-06-12 10:21:26 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-06-12 10:22:43 -0700
commit7b17350a1bfa527358e722baf962a5f9cfb838ea (patch)
treecdeb5835ddac84c6089dae28b52cbbab1d870140 /django
parent9980f67154ed3b10493e159d62c72ab6394769fe (diff)
Fixed #22823 (and partly #22563) - FKs from unmigrated apps breaking state.
Thanks to bendavis78 for the test and diagnostic work.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/state.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 40bb279cfc..750383c39f 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -44,11 +44,13 @@ class ProjectState(object):
# Any apps in self.real_apps should have all their models included
# in the render. We don't use the original model instances as there
# are some variables that refer to the Apps object.
+ # FKs/M2Ms from real apps are also not included as they just
+ # mess things up with partial states (due to lack of dependencies)
real_models = []
for app_label in self.real_apps:
app = global_apps.get_app_config(app_label)
for model in app.get_models():
- real_models.append(ModelState.from_model(model))
+ real_models.append(ModelState.from_model(model, exclude_rels=True))
# Populate the app registry with a stub for each application.
app_labels = set(model_state.app_label for model_state in self.models.values())
self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))])
@@ -155,13 +157,15 @@ class ModelState(object):
)
@classmethod
- def from_model(cls, model):
+ def from_model(cls, model, exclude_rels=False):
"""
Feed me a model, get a ModelState representing it out.
"""
# Deconstruct the fields
fields = []
for field in model._meta.local_fields:
+ if getattr(field, "rel", None) and exclude_rels:
+ continue
name, path, args, kwargs = field.deconstruct()
field_class = import_string(path)
try:
@@ -173,17 +177,18 @@ class ModelState(object):
model._meta.object_name,
e,
))
- for field in model._meta.local_many_to_many:
- name, path, args, kwargs = field.deconstruct()
- field_class = import_string(path)
- try:
- fields.append((name, field_class(*args, **kwargs)))
- except TypeError as e:
- raise TypeError("Couldn't reconstruct m2m field %s on %s: %s" % (
- name,
- model._meta.object_name,
- e,
- ))
+ if not exclude_rels:
+ for field in model._meta.local_many_to_many:
+ name, path, args, kwargs = field.deconstruct()
+ field_class = import_string(path)
+ try:
+ fields.append((name, field_class(*args, **kwargs)))
+ except TypeError as e:
+ raise TypeError("Couldn't reconstruct m2m field %s on %s: %s" % (
+ name,
+ model._meta.object_name,
+ e,
+ ))
# Extract the options
options = {}
for name in DEFAULT_NAMES: