diff --git a/tests/constraints/models.py b/tests/constraints/models.py
index f8a4ebe675..faef2163bf 100644
a
|
b
|
|
1 | 1 | from django.db import models |
| 2 | from django.db.models.functions import Lower |
2 | 3 | |
3 | 4 | |
4 | 5 | class Product(models.Model): |
… |
… |
class UniqueConstraintInclude(models.Model):
|
107 | 108 | ] |
108 | 109 | |
109 | 110 | |
| 111 | class UniqueConstraintExpression(models.Model): |
| 112 | name = models.CharField(max_length=15) |
| 113 | |
| 114 | class Meta: |
| 115 | required_db_features = { |
| 116 | 'supports_table_check_constraints', |
| 117 | 'supports_covering_indexes', |
| 118 | } |
| 119 | constraints = [ |
| 120 | models.UniqueConstraint(Lower('name'), name='name_lower_unique'), |
| 121 | ] |
| 122 | |
| 123 | |
110 | 124 | class AbstractModel(models.Model): |
111 | 125 | age = models.IntegerField() |
112 | 126 | |
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py
index 3d59d07b24..7e52cb3c24 100644
a
|
b
|
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
10 | 10 | |
11 | 11 | from .models import ( |
12 | 12 | ChildModel, Product, UniqueConstraintConditionProduct, |
13 | | UniqueConstraintDeferrable, UniqueConstraintInclude, |
14 | | UniqueConstraintProduct, |
| 13 | UniqueConstraintDeferrable, UniqueConstraintExpression, |
| 14 | UniqueConstraintInclude, UniqueConstraintProduct, |
15 | 15 | ) |
16 | 16 | |
17 | 17 | |
… |
… |
class UniqueConstraintTests(TestCase):
|
561 | 561 | opclasses=['jsonb_path_ops'], |
562 | 562 | ) |
563 | 563 | |
| 564 | @skipUnlessDBFeature( |
| 565 | 'supports_table_check_constraints', |
| 566 | 'supports_covering_indexes', |
| 567 | ) |
| 568 | def test_expressions_validate_unique(self): |
| 569 | UniqueConstraintExpression.objects.create(name='Blah') |
| 570 | msg = 'Unique constraint expression with this ? already exists.' |
| 571 | instance = UniqueConstraintExpression(name='BlAh') |
| 572 | with self.assertRaisesMessage(ValidationError, msg): |
| 573 | instance.validate_unique() |
| 574 | |
564 | 575 | def test_requires_name(self): |
565 | 576 | msg = 'A unique constraint must be named.' |
566 | 577 | with self.assertRaisesMessage(ValueError, msg): |