#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e0b4ea0a8-07997abd-9e04-48f3-ba3c-279e8a3bdbca-000000%40eu-central-1.amazonses.com.

Reply via email to