1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.

This commit is contained in:
Simon Charette
2023-07-07 19:43:51 -04:00
committed by Mariusz Felisiak
parent 98cfb90182
commit 595a2abb58
13 changed files with 295 additions and 9 deletions

View File

@@ -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``
------------------------