summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-06-02 12:10:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-02 12:11:06 +0200
commit9fce76a237ddf19e167dcba53815cbfee586b928 (patch)
tree8329b86822516d526140dea991e308a52ab6c5b4 /django/db
parent0fb0355271518a291584fdbbc3b1f400117d704d (diff)
[4.1.x] Fixed #31788 -- Fixed migration optimization after altering field to ManyToManyField.
This makes AddField() used for altering to ManyToManyField, dependent on the prior RemoveField. Backport of 798b6c23ee52c675dd0f0e233c50cddd7ff15657 from main
Diffstat (limited to 'django/db')
-rw-r--r--django/db/migrations/autodetector.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 5f41053283..4bcbae8bd3 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -1022,8 +1022,9 @@ class MigrationAutodetector:
def _generate_added_field(self, app_label, model_name, field_name):
field = self.to_state.models[app_label, model_name].get_field(field_name)
- # Fields that are foreignkeys/m2ms depend on stuff
- dependencies = []
+ # Adding a field always depends at least on its removal.
+ dependencies = [(app_label, model_name, field_name, False)]
+ # Fields that are foreignkeys/m2ms depend on stuff.
if field.remote_field and field.remote_field.model:
dependencies.extend(
self._get_dependencies_for_foreign_key(