diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/constraints.txt | 25 | ||||
| -rw-r--r-- | docs/releases/2.2.txt | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index 9e24a1cad8..5c94ce094a 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -43,3 +43,28 @@ ensures the age field is never less than 18. .. attribute:: CheckConstraint.name The name of the constraint. + +``UniqueConstraint`` +==================== + +.. class:: UniqueConstraint(*, fields, name) + + Creates a unique constraint in the database. + +``fields`` +---------- + +.. attribute:: UniqueConstraint.fields + +A list of field names that specifies the unique set of columns you want the +constraint to enforce. + +For example ``UniqueConstraint(fields=['room', 'date'], name='unique_location')`` +ensures only one location can exist for each ``date``. + +``name`` +-------- + +.. attribute:: UniqueConstraint.name + +The name of the constraint. diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index ef68c31eab..8a7a75a0bc 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -33,7 +33,8 @@ What's new in Django 2.2 Constraints ----------- -The new :class:`~django.db.models.CheckConstraint` class enables adding custom +The new :class:`~django.db.models.CheckConstraint` and +:class:`~django.db.models.UniqueConstraint` classes enable adding custom database constraints. Constraints are added to models using the :attr:`Meta.constraints <django.db.models.Options.constraints>` option. |
