Fixed #29641 -- Added support for unique constraints in Meta.constraints.

This constraint is similar to Meta.unique_together but also allows
specifying a name.

Co-authored-by: Ian Foote <python@ian.feete.org>
This commit is contained in:
Simon Charette 2018-08-05 22:30:44 -04:00 committed by Tim Graham
parent 8eae094638
commit db13bca60a
7 changed files with 126 additions and 5 deletions

View file

@ -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.