summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests/test_models.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-07-07 19:43:51 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-19 21:42:27 +0200
commit595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1 (patch)
treef08cf5a71a9d637818d896a7b31b2d7860e336ca /tests/invalid_models_tests/test_models.py
parent98cfb90182a8baa806fc4e09e294b6cfc5d09eff (diff)
Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.
Diffstat (limited to 'tests/invalid_models_tests/test_models.py')
-rw-r--r--tests/invalid_models_tests/test_models.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index 9e2a37b79a..dc52f58c44 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -2753,6 +2753,52 @@ class ConstraintsTests(TestCase):
self.assertEqual(Model.check(databases=self.databases), [])
+ def test_unique_constraint_nulls_distinct(self):
+ class Model(models.Model):
+ name = models.CharField(max_length=10)
+
+ class Meta:
+ constraints = [
+ models.UniqueConstraint(
+ fields=["name"],
+ name="name_uq_distinct_null",
+ nulls_distinct=True,
+ ),
+ ]
+
+ warn = Warning(
+ f"{connection.display_name} does not support unique constraints with nulls "
+ "distinct.",
+ hint=(
+ "A constraint won't be created. Silence this warning if you don't care "
+ "about it."
+ ),
+ obj=Model,
+ id="models.W047",
+ )
+ expected = (
+ []
+ if connection.features.supports_nulls_distinct_unique_constraints
+ else [warn]
+ )
+ self.assertEqual(Model.check(databases=self.databases), expected)
+
+ def test_unique_constraint_nulls_distinct_required_db_features(self):
+ class Model(models.Model):
+ name = models.CharField(max_length=10)
+
+ class Meta:
+ constraints = [
+ models.UniqueConstraint(
+ fields=["name"],
+ name="name_uq_distinct_null",
+ nulls_distinct=True,
+ ),
+ ]
+ required_db_features = {"supports_nulls_distinct_unique_constraints"}
+
+ self.assertEqual(Model.check(databases=self.databases), [])
+
@skipUnlessDBFeature("supports_expression_indexes")
def test_func_unique_constraint_expression_custom_lookup(self):
class Model(models.Model):