﻿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
35271	Old migrations with UniqueConstraint fail when using psycopg3	Adam Zahradník	nobody	"We have noticed that migrations generated with Django 4.0.6 containing UniqueConstraint fail to apply under Django 5.0.3 when using psycopg3.

The problematic operation:
{{{
migrations.AddConstraint(
    model_name=""model"",
    constraint=models.UniqueConstraint(
       [""some"", ""fields"", ""here""],
       name=""constraint_name"",
    ),
),
}}}

Which fails with the following error:
{{{
psycopg.errors.UndefinedObject: data type unknown has no default operator class for access method ""btree""
HINT:  You must specify an operator class for the index or define a default operator class for the data type.
}}}

However, when using psycopg2, the migration gets applied without any problem.

We also noticed that a migration generated by Django 4.1.5 produces the following operation, which runs successfully on both psycopg versions:
{{{
migrations.AddConstraint(
    model_name=""model"",
    constraint=models.UniqueConstraint(
        models.F(""some""),
        models.F(""fields""),
        models.F(""here""),
        name=""constraint_name"",
    ),
),
}}}

A current way to fix failing migrations is to pass the list of fields to a keyword argument `fields`:
{{{
migrations.AddConstraint(
    model_name=""model"",
    constraint=models.UniqueConstraint(
       fields=[""some"", ""fields"", ""here""],
       name=""constraint_name"",
    ),
),
}}}"	Bug	closed	Migrations	5.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
