diff options
| author | Simon Charette <simon.charette@zapier.com> | 2019-10-13 21:54:10 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-14 08:27:36 +0200 |
| commit | bab3ad54ff30848a16f08d72e70d8edbab019a63 (patch) | |
| tree | dccef67417067bd3e9cd182bbd9ec9de1c060714 /django | |
| parent | e0a869b208750e179e0924337af1c06929eff72a (diff) | |
[3.0.x] Fixed #30868 -- Prevented unnecessary AlterField when renaming a referenced pk.
Regression introduced by dcdd219ee1, refs #25817.
Thanks Carlos E. C. Leite for the report and Mariusz for the bisect.
Backport of 2839659b42ef80038152768b6cedae1016c59d90 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/autodetector.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 1c40161c7f..b2db84ffcb 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -927,6 +927,10 @@ class MigrationAutodetector: if remote_field_name: to_field_rename_key = rename_key + (remote_field_name,) if to_field_rename_key in self.renamed_fields: + # Repoint both model and field name because to_field + # inclusion in ForeignKey.deconstruct() is based on + # both. + new_field.remote_field.model = old_field.remote_field.model new_field.remote_field.field_name = old_field.remote_field.field_name # Handle ForeignObjects which can have multiple from_fields/to_fields. from_fields = getattr(new_field, 'from_fields', None) |
