summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/checks.txt2
-rw-r--r--docs/ref/models/constraints.txt22
-rw-r--r--docs/releases/5.0.txt3
3 files changed, 26 insertions, 1 deletions
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index 9e1381c31f..a208114596 100644
--- a/docs/ref/checks.txt
+++ b/docs/ref/checks.txt
@@ -408,6 +408,8 @@ Models
expression and won't be validated during the model ``full_clean()``.
* **models.W046**: ``<database>`` does not support comments on tables
(``db_table_comment``).
+* **models.W047**: ``<database>`` does not support unique constraints with
+ nulls distinct.
Security
--------
diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt
index 4ed5b65d46..efe63a8ac1 100644
--- a/docs/ref/models/constraints.txt
+++ b/docs/ref/models/constraints.txt
@@ -131,7 +131,7 @@ ensures the age field is never less than 18.
``UniqueConstraint``
====================
-.. class:: UniqueConstraint(*expressions, fields=(), name=None, condition=None, deferrable=None, include=None, opclasses=(), violation_error_code=None, violation_error_message=None)
+.. class:: UniqueConstraint(*expressions, fields=(), name=None, condition=None, deferrable=None, include=None, opclasses=(), nulls_distinct=None, violation_error_code=None, violation_error_message=None)
Creates a unique constraint in the database.
@@ -254,6 +254,26 @@ creates a unique index on ``username`` using ``varchar_pattern_ops``.
``opclasses`` are ignored for databases besides PostgreSQL.
+``nulls_distinct``
+------------------
+
+.. versionadded:: 5.0
+
+.. attribute:: UniqueConstraint.nulls_distinct
+
+Whether rows containing ``NULL`` values covered by the unique constraint should
+be considered distinct from each other. The default value is ``None`` which
+uses the database default which is ``True`` on most backends.
+
+For example::
+
+ UniqueConstraint(name="ordering", fields=["ordering"], nulls_distinct=False)
+
+creates a unique constraint that only allows one row to store a ``NULL`` value
+in the ``ordering`` column.
+
+``nulls_distinct`` is ignored for databases besides PostgreSQL 15+.
+
``violation_error_code``
------------------------
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index e4c1eac1d9..815fb062b4 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -361,6 +361,9 @@ Models
set the primary key on each model instance when the ``update_conflicts``
parameter is enabled (if the database supports it).
+* The new :attr:`.UniqueConstraint.nulls_distinct` attribute allows customizing
+ the treatment of ``NULL`` values on PostgreSQL 15+.
+
Pagination
~~~~~~~~~~