diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-06-08 16:56:46 -0400 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-23 14:06:14 +0200 |
| commit | b2407e4d7d25e4a5839bb512cb2fdf71e9e30a21 (patch) | |
| tree | 17f342173f8d492389d05f1ca6b75ab3ed960ce5 /django | |
| parent | 54402a75296909b1b00df41ff4dbd95e3d8a87e6 (diff) | |
Fixed #35305 -- Avoided recreating constraints on fields renamed via db_column.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/autodetector.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 13fe8f01a4..1d25101219 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -1460,6 +1460,29 @@ class MigrationAutodetector: for attr in new_constraint.non_db_attrs: new_kwargs.pop(attr, None) + # Replace renamed fields if the db_column is preserved. + for ( + _, + _, + rem_db_column, + rem_field_name, + _, + _, + field, + field_name, + ) in self.renamed_operations: + if field.db_column and rem_db_column == field.db_column: + new_fields = new_kwargs["fields"] + try: + new_field_idx = new_fields.index(field_name) + except ValueError: + continue + new_kwargs["fields"] = tuple( + new_fields[:new_field_idx] + + (rem_field_name,) + + new_fields[new_field_idx + 1 :] + ) + return (old_path, old_args, old_kwargs) != (new_path, new_args, new_kwargs) def create_altered_constraints(self): |
