diff options
| author | James Beith <james@beith.co.uk> | 2022-09-07 13:53:37 +1000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-07 09:17:23 +0200 |
| commit | 7ba9a448316de976735c1b14d069ed033ebed6ea (patch) | |
| tree | e1fd99f1361e60996c21e6e13224a1119f211050 /tests/postgres_tests | |
| parent | 4987ce33504fce35147ca416687323a7e1c9f2b3 (diff) | |
[4.1.x] Fixed #33982 -- Fixed migrations crash when adding model with ExclusionConstraint.
Regression in 0e656c02fe945389246f0c08f51c6db4a0849bd2.
Backport of 19e838daa8872ee29fbea0bc471c2a6443f26835 from main
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_constraints.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py index c5100542a4..2850d0eb3d 100644 --- a/tests/postgres_tests/test_constraints.py +++ b/tests/postgres_tests/test_constraints.py @@ -10,12 +10,14 @@ from django.db.models import ( F, Func, IntegerField, + Model, Q, UniqueConstraint, ) from django.db.models.fields.json import KeyTextTransform from django.db.models.functions import Cast, Left, Lower from django.test import ignore_warnings, modify_settings, skipUnlessDBFeature +from django.test.utils import isolate_apps from django.utils import timezone from django.utils.deprecation import RemovedInDjango50Warning @@ -1166,6 +1168,29 @@ class ExclusionConstraintTests(PostgreSQLTestCase): editor.add_constraint(Room, constraint) self.assertIn(constraint_name, self.get_constraints(Room._meta.db_table)) + @isolate_apps("postgres_tests") + def test_table_create(self): + constraint_name = "exclusion_equal_number_tc" + + class ModelWithExclusionConstraint(Model): + number = IntegerField() + + class Meta: + app_label = "postgres_tests" + constraints = [ + ExclusionConstraint( + name=constraint_name, + expressions=[("number", RangeOperators.EQUAL)], + ) + ] + + with connection.schema_editor() as editor: + editor.create_model(ModelWithExclusionConstraint) + self.assertIn( + constraint_name, + self.get_constraints(ModelWithExclusionConstraint._meta.db_table), + ) + @modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"}) class ExclusionConstraintOpclassesDepracationTests(PostgreSQLTestCase): |
