diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-06-16 15:09:27 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-06-16 15:10:07 -0700 |
| commit | 095f73aa224d46c67274104679bdc54f2a53499d (patch) | |
| tree | 6fac6857a89f93b60911e74f76b00eed629092a8 | |
| parent | 71f573330b76ebca21c65013e5b6e13e68c3e5ed (diff) | |
[1.7.x] Ignore more blank throughs on swapped-out M2Ms
| -rw-r--r-- | django/db/migrations/autodetector.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 8638faaf68..6b2cfdd19d 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -417,12 +417,14 @@ class MigrationAutodetector(object): if field.rel: if field.rel.to: related_fields[field.name] = field - if hasattr(field.rel, "through") and not field.rel.through._meta.auto_created: + # through will be none on M2Ms on swapped-out models; + # we can treat lack of through as auto_created=True, though. + if getattr(field.rel, "through", None) and not field.rel.through._meta.auto_created: related_fields[field.name] = field for field in self.new_apps.get_model(app_label, model_name)._meta.local_many_to_many: if field.rel.to: related_fields[field.name] = field - if hasattr(field.rel, "through") and not field.rel.through._meta.auto_created: + if getattr(field.rel, "through", None) and not field.rel.through._meta.auto_created: related_fields[field.name] = field # Are there unique/index_together to defer? unique_together = model_state.options.pop('unique_together', None) @@ -567,12 +569,14 @@ class MigrationAutodetector(object): if field.rel: if field.rel.to: related_fields[field.name] = field - if hasattr(field.rel, "through") and not field.rel.through._meta.auto_created: + # through will be none on M2Ms on swapped-out models; + # we can treat lack of through as auto_created=True, though. + if getattr(field.rel, "through", None) and not field.rel.through._meta.auto_created: related_fields[field.name] = field for field in model._meta.local_many_to_many: if field.rel.to: related_fields[field.name] = field - if hasattr(field.rel, "through") and not field.rel.through._meta.auto_created: + if getattr(field.rel, "through", None) and not field.rel.through._meta.auto_created: related_fields[field.name] = field # Generate option removal first unique_together = model_state.options.pop('unique_together', None) |
