1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

Fixed #23014: Renaming not atomic with unique together

This commit is contained in:
Andrew Godwin
2014-07-21 11:36:34 +01:00
parent 7dacc6ae46
commit e24e9e0438
4 changed files with 46 additions and 5 deletions

View File

@@ -162,9 +162,17 @@ class RenameField(Operation):
self.new_name = new_name
def state_forwards(self, app_label, state):
# Rename the field
state.models[app_label, self.model_name.lower()].fields = [
(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
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']
]
def database_forwards(self, app_label, schema_editor, from_state, to_state):
from_model = from_state.render().get_model(app_label, self.model_name)