summaryrefslogtreecommitdiff
path: root/tests/constraints
diff options
context:
space:
mode:
Diffstat (limited to 'tests/constraints')
-rw-r--r--tests/constraints/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py
index 20a5357cc5..bff8de8566 100644
--- a/tests/constraints/tests.py
+++ b/tests/constraints/tests.py
@@ -361,6 +361,22 @@ class CheckConstraintTests(TestCase):
constraint_with_pk.validate(ChildModel, ChildModel(id=1, age=1))
constraint_with_pk.validate(ChildModel, ChildModel(pk=1, age=1), exclude={"pk"})
+ def test_validate_fk_attname(self):
+ constraint_with_fk = models.CheckConstraint(
+ condition=models.Q(uniqueconstraintproduct_ptr_id__isnull=False),
+ name="parent_ptr_present",
+ )
+ with self.assertRaisesMessage(
+ ValidationError, "Constraint “parent_ptr_present” is violated."
+ ):
+ constraint_with_fk.validate(
+ ChildUniqueConstraintProduct, ChildUniqueConstraintProduct()
+ )
+ constraint_with_fk.validate(
+ ChildUniqueConstraintProduct,
+ ChildUniqueConstraintProduct(uniqueconstraintproduct_ptr_id=1),
+ )
+
@skipUnlessDBFeature("supports_json_field")
def test_validate_jsonfield_exact(self):
data = {"release": "5.0.2", "version": "stable"}