Fixed #30397 -- Added app_label/class interpolation for names of indexes and constraints.

This commit is contained in:
can 2019-07-05 15:15:41 +03:00 committed by Mariusz Felisiak
parent 8233144ca0
commit febe136d4c
9 changed files with 166 additions and 11 deletions

View file

@ -25,8 +25,11 @@ option.
cannot normally specify a constraint on an abstract base class, since the
:attr:`Meta.constraints <django.db.models.Options.constraints>` option is
inherited by subclasses, with exactly the same values for the attributes
(including ``name``) each time. Instead, specify the ``constraints`` option
on subclasses directly, providing a unique name for each constraint.
(including ``name``) each time. To work around name collisions, part of the
name may contain ``'%(app_label)s'`` and ``'%(class)s'``, which are
replaced, respectively, by the lowercased app label and class name of the
concrete model. For example ``CheckConstraint(check=Q(age__gte=18),
name='%(app_label)s_%(class)s_is_adult')``.
.. admonition:: Validation of Constraints
@ -63,6 +66,10 @@ ensures the age field is never less than 18.
The name of the constraint.
.. versionchanged:: 3.0
Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added.
``UniqueConstraint``
====================
@ -89,6 +96,10 @@ date.
The name of the constraint.
.. versionchanged:: 3.0
Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added.
``condition``
-------------

View file

@ -55,9 +55,15 @@ than 30 characters and shouldn't start with a number (0-9) or underscore (_).
cannot normally specify a partial index on an abstract base class, since
the :attr:`Meta.indexes <django.db.models.Options.indexes>` option is
inherited by subclasses, with exactly the same values for the attributes
(including ``name``) each time. Instead, specify the ``indexes`` option
on subclasses directly, providing a unique name for each index.
(including ``name``) each time. To work around name collisions, part of the
name may contain ``'%(app_label)s'`` and ``'%(class)s'``, which are
replaced, respectively, by the lowercased app label and class name of the
concrete model. For example ``Index(fields=['title'],
name='%(app_label)s_%(class)s_title_index')``.
.. versionchanged:: 3.0
Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added.
``db_tablespace``
-----------------