#34898: Adding non-deterministic collations to unique CharFields crashes on
PostgreSQL.
--------------------------------------+------------------------------------
     Reporter:  Mariusz Felisiak      |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  Migrations            |                  Version:  4.2
     Severity:  Normal                |               Resolution:
     Keywords:  PostgreSQL collation  |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Tom Carrick):

 Interesting. I looked into it and it is indeed only this case that breaks.

 If you add them both at once, it's fine. If you add the collation, then
 the unique, it's fine. But if it's unique, then you try to add the
 collation, boom.

 As you might expect, this also happens for `db_index`.

 However, it doesn't happen when using `Meta` `indexes` / `constraints`
 unless you have `opclasses=["varchar_pattern_ops"]`, and if you remove
 this in the same migration as adding the collation, this also seems to
 work fine (I'm not sure if by luck of because Django first removes the
 constrain, then does other stuff, then adds the constraint purposefully).

 Given that `db_index` is discouraged in the docs... and I'd make the same
 argument for doing the same for `unique=True`, maybe a note in the docs
 about this is enough?

 I didn't look very hard to find a solution, but I think it should be
 possible by adding stuff to
 `django.db.backends.postgresql.schema.DatabaseSchemaEditor._alter_field`.
 I'll take a look.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34898#comment:1>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018b6ccdcf5a-04435c73-e4c0-4e85-8e1f-ab3dd90b153a-000000%40eu-central-1.amazonses.com.

Reply via email to