summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNan Liu <45443761+nanlliu@users.noreply.github.com>2020-05-24 08:59:46 +0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-26 08:34:14 +0200
commit114da2d0455594bae0bbda8f2b1d46c5ec854956 (patch)
tree1c93443ae4feb00a7cea559227b1cee569df48c1 /tests
parentccf3cecbaf7cdaeeb027ca37bd93efb35ff7393b (diff)
[3.1.x] Fixed #31416 -- Made autodetector find dependencies for MTI model creation on base fields removal.
Removing a base field must take place before adding a new inherited model that has a field with the same name. Backport of 33c365781abbcc1b21a31b31d95d344a174df0d5 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index daff57fc2c..10af72561b 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2454,3 +2454,28 @@ class AutodetectorTests(TestCase):
self.assertNumberMigrations(changes, 'app', 1)
self.assertOperationTypes(changes, 'app', 0, ['DeleteModel'])
self.assertOperationAttributes(changes, 'app', 0, 0, name='Dog')
+
+ def test_add_model_with_field_removed_from_base_model(self):
+ """
+ Removing a base field takes place before adding a new inherited model
+ that has a field with the same name.
+ """
+ before = [
+ ModelState('app', 'readable', [
+ ('id', models.AutoField(primary_key=True)),
+ ('title', models.CharField(max_length=200)),
+ ]),
+ ]
+ after = [
+ ModelState('app', 'readable', [
+ ('id', models.AutoField(primary_key=True)),
+ ]),
+ ModelState('app', 'book', [
+ ('title', models.CharField(max_length=200)),
+ ], bases=('app.readable',)),
+ ]
+ changes = self.get_changes(before, after)
+ self.assertNumberMigrations(changes, 'app', 1)
+ self.assertOperationTypes(changes, 'app', 0, ['RemoveField', 'CreateModel'])
+ self.assertOperationAttributes(changes, 'app', 0, 0, name='title', model_name='readable')
+ self.assertOperationAttributes(changes, 'app', 0, 1, name='book')