diff options
| author | Salvo Polizzi <salvopolizzi03@gmail.com> | 2024-11-28 13:52:25 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-11-28 17:40:52 +0100 |
| commit | b92511b47475ce7fa1626d7d8c6180ae84bf0a19 (patch) | |
| tree | 06f18aee5d221b93d066aa8065a1bb8d6da11e3a /tests/migrations | |
| parent | 1722f2db5808708de6fc6e0f48af2d518be1e348 (diff) | |
Refs #35038 -- Added test for drop and recreation of a constraint.
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index d4345208ca..d93114564a 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2981,6 +2981,43 @@ class AutodetectorTests(BaseAutodetectorTests): changes, "testapp", 0, 0, model_name="author", name="name_contains_bob" ) + def test_constraint_dropped_and_recreated(self): + altered_constraint = models.CheckConstraint( + condition=models.Q(name__contains="bob"), + name="name_contains_bob", + ) + author_name_check_constraint_lowercased = copy.deepcopy( + self.author_name_check_constraint + ) + author_name_check_constraint_lowercased.options = { + "constraints": [altered_constraint] + } + changes = self.get_changes( + [self.author_name_check_constraint], + [author_name_check_constraint_lowercased], + ) + + self.assertNumberMigrations(changes, "testapp", 1) + self.assertOperationTypes( + changes, "testapp", 0, ["RemoveConstraint", "AddConstraint"] + ) + self.assertOperationAttributes( + changes, + "testapp", + 0, + 0, + model_name="author", + name="name_contains_bob", + ) + self.assertOperationAttributes( + changes, + "testapp", + 0, + 1, + model_name="author", + constraint=altered_constraint, + ) + def test_add_unique_together(self): """Tests unique_together detection.""" changes = self.get_changes( |
