diff options
Diffstat (limited to 'tests/invalid_models_tests/test_models.py')
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 6c3017ff47..958ad120ca 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -1695,6 +1695,27 @@ class ConstraintsTests(TestCase): ]) @skipUnlessDBFeature('supports_table_check_constraints') + def test_check_constraint_pointing_to_reverse_o2o(self): + class Model(models.Model): + parent = models.OneToOneField('self', models.CASCADE) + + class Meta: + constraints = [ + models.CheckConstraint( + name='name', + check=models.Q(model__isnull=True), + ), + ] + + self.assertEqual(Model.check(databases=self.databases), [ + Error( + "'constraints' refers to the nonexistent field 'model'.", + obj=Model, + id='models.E012', + ), + ]) + + @skipUnlessDBFeature('supports_table_check_constraints') def test_check_constraint_pointing_to_m2m_field(self): class Model(models.Model): m2m = models.ManyToManyField('self') @@ -1943,6 +1964,28 @@ class ConstraintsTests(TestCase): ) ] if connection.features.supports_partial_indexes else []) + def test_unique_constraint_pointing_to_reverse_o2o(self): + class Model(models.Model): + parent = models.OneToOneField('self', models.CASCADE) + + class Meta: + required_db_features = {'supports_partial_indexes'} + constraints = [ + models.UniqueConstraint( + fields=['parent'], + name='name', + condition=models.Q(model__isnull=True), + ), + ] + + self.assertEqual(Model.check(databases=self.databases), [ + Error( + "'constraints' refers to the nonexistent field 'model'.", + obj=Model, + id='models.E012', + ), + ] if connection.features.supports_partial_indexes else []) + def test_deferrable_unique_constraint(self): class Model(models.Model): age = models.IntegerField() |
