1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.7.x] Fixed #23859 -- Fixed a migration crash when a field is renamed that is part of an index_together

Backport of 7b4a994599 from master.
This commit is contained in:
Markus Holtermann
2014-11-17 19:04:38 +01:00
committed by Carl Meyer
parent 49d4095767
commit 03d983f7c3
3 changed files with 16 additions and 8 deletions

View File

@@ -177,13 +177,14 @@ class RenameField(Operation):
(self.new_name if n == self.old_name else n, f)
for n, f in state.models[app_label, self.model_name.lower()].fields
]
# Fix unique_together to refer to the new field
# Fix index/unique_together to refer to the new field
options = state.models[app_label, self.model_name.lower()].options
if "unique_together" in options:
options['unique_together'] = [
[self.new_name if n == self.old_name else n for n in unique]
for unique in options['unique_together']
]
for option in ('index_together', 'unique_together'):
if option in options:
options[option] = [
[self.new_name if n == self.old_name else n for n in together]
for together in options[option]
]
def database_forwards(self, app_label, schema_editor, from_state, to_state):
to_model = to_state.render().get_model(app_label, self.model_name)