#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 Ed Chai):

 Replying to [comment:13 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
 > BEGIN;
 > --
 > -- Create model ExtendedUser
 > --
 > CREATE TABLE "myapp_extendeduser" ("id" bigint NOT NULL PRIMARY KEY
 GENERATED BY DEFAULT AS IDENTITY, "user_id" varchar(30) COLLATE "ci" NOT
 NULL UNIQUE);
 > ALTER TABLE "myapp_extendeduser" ADD CONSTRAINT
 "myapp_extendeduser_user_id_<chars>_fk_myapp_user_username" FOREIGN KEY
 ("user_id") REFERENCES "myapp_user" ("username") DEFERRABLE INITIALLY
 DEFERRED;
 > CREATE INDEX "myapp_extendeduser_user_id_<chars>_like" ON
 "myapp_extendeduser" ("user_id" varchar_pattern_ops);
 > COMMIT;
 > }}}
 >
 > (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
 > }}}
 I think your code is not related to this issue.  This ticket only
 addresses errors that occur when both db_collation and unique are applied
 on Postgres.  `CREATE INDEX` is the expected operation when you create
 foreign keys

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33901#comment:15>
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/010701879fa781ec-ea3fede7-611c-459c-a5c3-b955e955bec4-000000%40eu-central-1.amazonses.com.

Reply via email to