﻿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
32838	Migrations create extra index when foreign key is also part of a unique constraint	Lev	nobody	"Given a model like so:


{{{
class Person(models.Model):
    name = models.TextField()

class Address(models.Model):
    person = models.ForeignKey(Person, on_delete=models.PROTECT)
    street = models.TextField()

    class Meta:
       unique_together = [""person"", ""street""]
}}}

and a Postgres backend, Django will create two btree indexes, one on the foreign key ""person"" and another on ""person, street"" to enforce the unique constraint. In this case, the ""person"" index is redundant and wasteful since the ""person, street"" index is sufficient. We can check for the foreign key index being covered by the unique index and not create it if that's the case.

"	Cleanup/optimization	closed	Database layer (models, ORM)	3.2	Normal	wontfix	postgres,indexes,unique constraint,foreign keys		Unreviewed	0	0	0	0	0	0
