diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/checks.txt | 2 | ||||
| -rw-r--r-- | docs/ref/models/constraints.txt | 34 | ||||
| -rw-r--r-- | docs/releases/3.1.txt | 3 |
3 files changed, 38 insertions, 1 deletions
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index d9b56c3c58..daf651392f 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -354,6 +354,8 @@ Models * **models.W036**: ``<database>`` does not support unique constraints with conditions. * **models.W037**: ``<database>`` does not support indexes with conditions. +* **models.W038**: ``<database>`` does not support deferrable unique + constraints. Security -------- diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index 9e3119f600..00e907a882 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -76,7 +76,7 @@ The name of the constraint. ``UniqueConstraint`` ==================== -.. class:: UniqueConstraint(*, fields, name, condition=None) +.. class:: UniqueConstraint(*, fields, name, condition=None, deferrable=None) Creates a unique constraint in the database. @@ -119,3 +119,35 @@ ensures that each user only has one draft. These conditions have the same database restrictions as :attr:`Index.condition`. + +``deferrable`` +-------------- + +.. attribute:: UniqueConstraint.deferrable + +.. versionadded:: 3.1 + +Set this parameter to create a deferrable unique constraint. Accepted values +are ``Deferrable.DEFERRED`` or ``Deferrable.IMMEDIATE``. For example:: + + from django.db.models import Deferrable, UniqueConstraint + + UniqueConstraint( + name='unique_order', + fields=['order'], + deferrable=Deferrable.DEFERRED, + ) + +By default constraints are not deferred. A deferred constraint will not be +enforced until the end of the transaction. An immediate constraint will be +enforced immediately after every command. + +.. admonition:: MySQL, MariaDB, and SQLite. + + Deferrable unique constraints are ignored on MySQL, MariaDB, and SQLite as + neither supports them. + +.. warning:: + + Deferred unique constraints may lead to a `performance penalty + <https://www.postgresql.org/docs/current/sql-createtable.html#id-1.9.3.85.9.4>`_. diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 1de4f24684..ae482f0129 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -381,6 +381,9 @@ Models <sqlite3.Connection.create_function>` on Python 3.8+. This allows using them in check constraints and partial indexes. +* The new :attr:`.UniqueConstraint.deferrable` attribute allows creating + deferrable unique constraints. + Pagination ~~~~~~~~~~ |
