summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJeff <jeffrey.yancey@gmail.com>2018-05-23 15:55:27 -0400
committerTim Graham <timograham@gmail.com>2018-06-15 12:07:40 -0400
commit2b7b199390336f7068ef8cb8d67b2e83fb6b818e (patch)
tree3b2358011320ac23c353797584e8fcec7b4689a3 /django
parent0eca99dadeed76bf0ac1a3cf4b62926ae5717319 (diff)
[2.1.x] Fixed #29000 -- Fixed RenameModel's renaming of a M2M column when run after RenameField.
Regression in 45ded053b1f4320284aa5dac63052f6d1baefea9. Backport of fcc4e251dbc917118f73d7187ee2f4cbf3883f36 from master
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/fields.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/django/db/migrations/operations/fields.py b/django/db/migrations/operations/fields.py
index 96b0045744..a41b3444e5 100644
--- a/django/db/migrations/operations/fields.py
+++ b/django/db/migrations/operations/fields.py
@@ -271,15 +271,10 @@ class RenameField(FieldOperation):
# Rename the field
fields = model_state.fields
found = False
+ delay = True
for index, (name, field) in enumerate(fields):
if not found and name == self.old_name:
fields[index] = (self.new_name, field)
- # Delay rendering of relationships if it's not a relational
- # field and not referenced by a foreign key.
- delay = (
- not field.is_relation and
- not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
- )
found = True
# Fix from_fields to refer to the new field.
from_fields = getattr(field, 'from_fields', None)
@@ -288,6 +283,12 @@ class RenameField(FieldOperation):
self.new_name if from_field_name == self.old_name else from_field_name
for from_field_name in from_fields
])
+ # Delay rendering of relationships if it's not a relational
+ # field and not referenced by a foreign key.
+ delay = delay and (
+ not field.is_relation and
+ not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
+ )
if not found:
raise FieldDoesNotExist(
"%s.%s has no field named '%s'" % (app_label, self.model_name, self.old_name)