diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/postgres/constraints.txt | 12 | ||||
| -rw-r--r-- | docs/ref/models/constraints.txt | 32 |
2 files changed, 40 insertions, 4 deletions
diff --git a/docs/ref/contrib/postgres/constraints.txt b/docs/ref/contrib/postgres/constraints.txt index fcf50b8b5f..abc5e4e4e4 100644 --- a/docs/ref/contrib/postgres/constraints.txt +++ b/docs/ref/contrib/postgres/constraints.txt @@ -12,7 +12,7 @@ PostgreSQL supports additional data integrity constraints available from the ``ExclusionConstraint`` ======================= -.. class:: ExclusionConstraint(*, name, expressions, index_type=None, condition=None, deferrable=None, include=None, violation_error_message=None) +.. class:: ExclusionConstraint(*, name, expressions, index_type=None, condition=None, deferrable=None, include=None, violation_error_code=None, violation_error_message=None) Creates an exclusion constraint in the database. Internally, PostgreSQL implements exclusion constraints using indexes. The default index type is @@ -133,6 +133,16 @@ used for queries that select only included fields ``include`` is supported for GiST indexes. PostgreSQL 14+ also supports ``include`` for SP-GiST indexes. +``violation_error_code`` +------------------------ + +.. versionadded:: 5.0 + +.. attribute:: ExclusionConstraint.violation_error_code + +The error code used when ``ValidationError`` is raised during +:ref:`model validation <validating-objects>`. Defaults to ``None``. + ``violation_error_message`` --------------------------- diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index baaacd8754..f248de0315 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -48,7 +48,7 @@ option. ``BaseConstraint`` ================== -.. class:: BaseConstraint(*, name, violation_error_message=None) +.. class:: BaseConstraint(* name, violation_error_code=None, violation_error_message=None) Base class for all constraints. Subclasses must implement ``constraint_sql()``, ``create_sql()``, ``remove_sql()`` and @@ -68,6 +68,16 @@ All constraints have the following parameters in common: The name of the constraint. You must always specify a unique name for the constraint. +``violation_error_code`` +------------------------ + +.. versionadded:: 5.0 + +.. attribute:: BaseConstraint.violation_error_code + +The error code used when ``ValidationError`` is raised during +:ref:`model validation <validating-objects>`. Defaults to ``None``. + ``violation_error_message`` --------------------------- @@ -94,7 +104,7 @@ This method must be implemented by a subclass. ``CheckConstraint`` =================== -.. class:: CheckConstraint(*, check, name, violation_error_message=None) +.. class:: CheckConstraint(*, check, name, violation_error_code=None, violation_error_message=None) Creates a check constraint in the database. @@ -121,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_message=None) +.. class:: UniqueConstraint(*expressions, fields=(), name=None, condition=None, deferrable=None, include=None, opclasses=(), violation_error_code=None, violation_error_message=None) Creates a unique constraint in the database. @@ -242,6 +252,22 @@ creates a unique index on ``username`` using ``varchar_pattern_ops``. ``opclasses`` are ignored for databases besides PostgreSQL. +``violation_error_code`` +------------------------ + +.. versionadded:: 5.0 + +.. attribute:: UniqueConstraint.violation_error_code + +The error code used when ``ValidationError`` is raised during +:ref:`model validation <validating-objects>`. Defaults to ``None``. + +This code is *not used* for :class:`UniqueConstraint`\s with +:attr:`~UniqueConstraint.fields` and without a +:attr:`~UniqueConstraint.condition`. Such :class:`~UniqueConstraint`\s have the +same error code as constraints defined with :attr:`.Field.unique` or in +:attr:`Meta.unique_together <django.db.models.Options.constraints>`. + ``violation_error_message`` --------------------------- |
