From db13bca60a6758d5fe63eeb01c00c3f54f650715 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 5 Aug 2018 22:30:44 -0400 Subject: 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 --- docs/ref/models/constraints.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'docs/ref') 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. -- cgit v1.3