From c226c6cb3209122b6732fd501e2994c408dc258e Mon Sep 17 00:00:00 2001 From: Ian Foote Date: Mon, 27 Aug 2018 03:25:06 +0100 Subject: Fixed #20581 -- Added support for deferrable unique constraints. --- docs/ref/models/constraints.txt | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'docs/ref/models') 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 + `_. -- cgit v1.3