summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-03-04 09:36:53 +0100
committerMarkus Holtermann <info@markusholtermann.eu>2015-03-04 14:26:49 +0100
commita9e29fae105d1ddd4e0ac2059cbe62b0ee348bc8 (patch)
tree0fbddf85ac51543bef69ccbc2278d26214b1cf31 /django
parent70123cf084e3af7dfc61bb7bd2090ff802c3cda4 (diff)
Fixed #24435 -- Prevented m2m field removal and addition in migrations when changing blank
Thanks Mark Tranchant for the report an Tim Graham for the test and review.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/autodetector.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 16df9bfd91..33a9e9e166 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -848,8 +848,16 @@ class MigrationAutodetector(object):
old_field_dec = self.deep_deconstruct(old_field)
new_field_dec = self.deep_deconstruct(new_field)
if old_field_dec != new_field_dec:
- if (not isinstance(old_field, models.ManyToManyField) and
- not isinstance(new_field, models.ManyToManyField)):
+ both_m2m = (
+ isinstance(old_field, models.ManyToManyField) and
+ isinstance(new_field, models.ManyToManyField)
+ )
+ neither_m2m = (
+ not isinstance(old_field, models.ManyToManyField) and
+ not isinstance(new_field, models.ManyToManyField)
+ )
+ if both_m2m or neither_m2m:
+ # Either both fields are m2m or neither is
preserve_default = True
if (old_field.null and not new_field.null and not new_field.has_default() and
not isinstance(new_field, models.ManyToManyField)):
@@ -870,6 +878,7 @@ class MigrationAutodetector(object):
)
)
else:
+ # We cannot alter between m2m and concrete fields
self._generate_removed_field(app_label, model_name, field_name)
self._generate_added_field(app_label, model_name, field_name)