diff options
| author | Sanskar Jaiswal <jaiswalsanskar078@gmail.com> | 2020-10-17 00:47:13 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-08 07:46:51 +0200 |
| commit | 8c3bd0b708b488a1f6e8bd8cc6b96569904605be (patch) | |
| tree | 4e6717eeccf185b2d4698aa4cdd51a7d6165418a /docs | |
| parent | 7f6a41d3d915feb01acfa08b2b936d1199db3ba6 (diff) | |
Fixed #31653 -- Added AddConstraintNotValid()/ValidateConstraint() operations for PostgreSQL.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/postgres/operations.txt | 36 | ||||
| -rw-r--r-- | docs/releases/4.0.txt | 9 |
2 files changed, 45 insertions, 0 deletions
diff --git a/docs/ref/contrib/postgres/operations.txt b/docs/ref/contrib/postgres/operations.txt index dc9faebcdb..4a0ef7a6b8 100644 --- a/docs/ref/contrib/postgres/operations.txt +++ b/docs/ref/contrib/postgres/operations.txt @@ -188,3 +188,39 @@ database. The ``CONCURRENTLY`` option is not supported inside a transaction (see :ref:`non-atomic migration <non-atomic-migrations>`). + +Adding constraints without enforcing validation +=============================================== + +.. versionadded:: 4.0 + +PostgreSQL supports the ``NOT VALID`` option with the ``ADD CONSTRAINT`` +statement to add check constraints without enforcing validation on existing +rows. This option is useful if you want to skip the potentially lengthy scan of +the table to verify that all existing rows satisfy the constraint. + +To validate check constraints created with the ``NOT VALID`` option at a later +point of time, use the +:class:`~django.contrib.postgres.operations.ValidateConstraint` operation. + +See `the PostgreSQL documentation <https://www.postgresql.org/docs/current/ +sql-altertable.html#SQL-ALTERTABLE-NOTES>`__ for more details. + +.. class:: AddConstraintNotValid(model_name, constraint) + + Like :class:`~django.db.migrations.operations.AddConstraint`, but avoids + validating the constraint on existing rows. + +.. class:: ValidateConstraint(model_name, name) + + Scans through the table and validates the given check constraint on + existing rows. + +.. note:: + + ``AddConstraintNotValid`` and ``ValidateConstraint`` operations should be + performed in two separate migrations. Performing both operations in the + same atomic migration has the same effect as + :class:`~django.db.migrations.operations.AddConstraint`, whereas performing + them in a single non-atomic migration, may leave your database in an + inconsistent state if the ``ValidateConstraint`` operation fails. diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index 60c449bc88..2bdb76ef3d 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -122,6 +122,15 @@ Minor features * The PostgreSQL backend now supports connecting by a service name. See :ref:`postgresql-connection-settings` for more details. +* The new :class:`~django.contrib.postgres.operations.AddConstraintNotValid` + operation allows creating check constraints on PostgreSQL without verifying + that all existing rows satisfy the new constraint. + +* The new :class:`~django.contrib.postgres.operations.ValidateConstraint` + operation allows validating check constraints which were created using + :class:`~django.contrib.postgres.operations.AddConstraintNotValid` on + PostgreSQL. + :mod:`django.contrib.redirects` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
