﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32932	Unique indexes	David Sanders	nobody	"Django already supports both unique constraints and indexes from the models Meta <3

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),
        )
}}}"	New feature	closed	Database layer (models, ORM)	3.2	Normal	duplicate			Unreviewed	0	0	0	0	0	0
