#33901: non-deterministic collations doesn't work with Unique=True on 
Postgres13.3
-------------------------------------+-------------------------------------
     Reporter:  Ed Chai              |                    Owner:  Ed Chai
         Type:  Bug                  |                   Status:  closed
    Component:  Migrations           |                  Version:  dev
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  collation unique     |             Triage Stage:  Ready for
  citext                             |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Petter Friberg):

 Not sure if there should be a new ticket here or not but I'm still seeing
 this on 4.2 when having a relation that points to a unique field with a
 non-deterministic collation.

 For instance, consider if we run the following migration operation:

 {{{
 #!python
 migrations.CreateModel(
     name="ExtendedUser",
     fields=[
         ('id', models.BigAutoField(auto_created=True, primary_key=True,
 serialize=False, verbose_name='ID')),
         ('user',
 models.OneToOneField(on_delete=django.db.models.deletion.CASCADE,
 to=settings.AUTH_USER_MODEL, to_field='username'))
     ]
 )
 }}}

 Running `manage.py sqlmigrate` for that operation displays the generated
 `_like` index

 {{{
 #!sql
 CREATE INDEX "myapp_extendeduser_user_id_<chars>_like" ON
 "myapp_extendeduser" ("user_id" varchar_pattern_ops);
 }}}

 (Not sure if there's more to it but) I think the
 
[https://code.djangoproject.com/changeset/f3f9d03edf17ccfa17263c7efa0b1350d1ac9278
 provided patch] could be extended with something like below to resolve at
 least `OneToOneField`

 {{{
 #!python
             # Non-deterministic collations on Postgresql don't support
 indexes
             # for operator classes varchar_pattern_ops/text_pattern_ops.
             if getattr(field, "db_collation", None) or (field.is_relation
 and getattr(field.target_field, "db_collation", None)):
                 return None
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33901#comment:13>
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/010701879dee203d-3a8535be-19d3-49ff-b03f-eebe31b40cd8-000000%40eu-central-1.amazonses.com.

Reply via email to