Django unique case insensitive field

Django documentations says:

Deprecated since version 4.2:CICharField is deprecated in favor of CharField(db_collation="…") with a case-insensitive non-deterministic collation.

link : PostgreSQL specific model fields | Django documentation | Django

What should I write in my code exactly ?

I wrote about the deprecation here: How to migrate from Django’s PostgreSQL CI Fields to use a case-insensitive collation - Adam Johnson

There was also a lot of post-deprecation discussion here: https://groups.google.com/g/django-developers/c/nDMnO98nexY . If you want to avoid changes, there‘s the django-citext package.

Also, Django 5.0 ships GeneratedField which I noted in this comment might provide a better alternative:

Django 5.0 will hopefully come with generated fields: https://github.com/django/django/pull/16417 . We may then be able to store the user-provided email in “email_original_cased” (or whatever) and make “email” a GeneratedField(expression=Lower(“email”)), with the lowercase collation and a unique consrtaint. We’ll have to see…