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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user