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:
committed by
Mariusz Felisiak
parent
98cfb90182
commit
595a2abb58
@@ -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``
|
||||
------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user