﻿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
29641	Add support for unique constraints to Meta.constraints	Simon Charette	Ian Foote	"Just like `Meta.indexes[Index]` allows more granularity over `Field.db_index=True`/ `Meta.index_together` we should make `Meta.constraints[UniqueConstraint]` an analog for `Field.unique=True`/`Meta.unique_together`.

This ticket proposes to introduce `django.db.constraint.UniqueConstraint(fields, name)` to allow such constraints to be defined with the sole extra feature of allowing a `name` to be specified.

The mid-term goal of this feature addition is to rely on the partial indices work (#29547) that is likely to land in 2.2 to allow partial unique constraints to be defined which is a really useful feature.


e.g.

{{{#!python
class Tweet(models.Model):
    user = models.ForeignKey(User, models.CASCADE)
    pinned = models.BooleanField(default=False)

    class Meta:
        constraints = [
            UniqueConstraint(
                fields=['user', 'pinned'],
                condition=Q(pinned=True),
                name='pinned_tweet'
            ),
        ]
}}}

Adding support for partial constraints should be tracked in a future ticket as this one will focus on refactoring the `CheckConstraint` work added for #11964 to the definition of different type of constraints."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		Ian Foote	Accepted	1	0	0	0	0	0
