#35271: Old migrations with UniqueConstraint fail when using psycopg3
------------------------------------------+------------------------
Reporter: Adam Zahradník | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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",
),
),
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/35271>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.