summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2018-08-27 03:25:06 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-30 10:43:50 +0200
commitc226c6cb3209122b6732fd501e2994c408dc258e (patch)
tree3a72f1403e4a061c9d4dbf0d7cd88639457f9df2 /docs/ref
parent555e3a848e7ac13580371c7eafbc89195fee6ea9 (diff)
Fixed #20581 -- Added support for deferrable unique constraints.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/checks.txt2
-rw-r--r--docs/ref/models/constraints.txt34
2 files changed, 35 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>`_.