A worthwhile addition would be to support _unique indexes_, if the
database makes this distinction.
In Postgres a unique index is a distinct feature from unique constraints;
unique indexes are the mechanism that enforces the unique constraints
declared for the table: https://www.postgresql.org/docs/current/indexes-
unique.html.
One important difference between the 2 is the fact that indexes may
support expressions whereas constraints do not (at least in PG).
An example may be to enforce a unique attribute in a jsonb field:
{{{
CREATE UNIQUE INDEX unique_attr ON some_table (
(some_json_field->>'some_attr') )
}}}
This could perhaps be a new option on the `Index` class:
{{{
class SomeTable(models.Model):
some_json_field = models.JSONField()
class Meta:
indexes = (
models.Index(models.RawSQL("some_json_field->>'some_attr'",
params=[]), name="unique_attr", unique=True),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
Django 4.0 will support functional unique constraints which are
implemented internally by unique indexes, see #30916 and
3aa545281e0c0f9fac93753e3769df9e0334dbaa. I don't think there is a need
for a new API.
Duplicate of #30916.
--
Ticket URL: <https://code.djangoproject.com/ticket/32932#comment:1>