Constraints reference
The classes defined in this module create database constraints. They are addedin the model option.
Constraints are defined in django.db.models.constraints
, but forconvenience they're imported into . The standardconvention is to use from django.db import models
and refer to theconstraints as models.<Foo>Constraint
.
- class
CheckConstraint
(*, check, name)[源代码] - Creates a check constraint in the database.
UniqueConstraint
- Creates a unique constraint in the database.
UniqueConstraint.
- A list of field names that specifies the unique set of columns you want theconstraint to enforce.
For example, UniqueConstraint(fields=['room', 'date'],
ensures each room can only be booked once for eachdate.
name='unique_booking')
UniqueConstraint.
name
- The name of the constraint.
These conditions have the same database restrictions as.