mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
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:
parent
8eae094638
commit
db13bca60a
7 changed files with 126 additions and 5 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue