# Django unique case insensitive field

**URL:** <https://forum.djangoproject.com/t/django-unique-case-insensitive-field/30371>\
**Category:** Using the ORM\
**Created:** [April 20, 2024, 9:57pm UTC](https://forum.djangoproject.com/t/django-unique-case-insensitive-field/30371 "2024-04-20T21:57:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bamdad-Mehrvarzan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bamdad-mehrvarzan/32/19086_2.png) [@Bamdad-Mehrvarzan](https://forum.djangoproject.com/u/Bamdad-Mehrvarzan)\
**Post date:** [April 20, 2024, 9:57pm UTC](https://forum.djangoproject.com/t/django-unique-case-insensitive-field/30371/1 "2024-04-20T21:57:56Z")

</div>

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](https://docs.djangoproject.com/en/5.0/ref/contrib/postgres/fields/#citext-fields)

What should I write in my code exactly ?

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 22, 2024, 10:11am UTC](https://forum.djangoproject.com/t/django-unique-case-insensitive-field/30371/2 "2024-04-22T10:11:07Z")

</div>

I wrote about the deprecation here: [How to migrate from Django’s PostgreSQL CI Fields to use a case-insensitive collation - Adam Johnson](https://adamj.eu/tech/2023/02/23/migrate-django-postgresql-ci-fields-case-insensitive-collation/)

There was also a lot of post-deprecation discussion here: [https://groups.google.com/g/django-developers/c/nDMnO98nexY](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](https://groups.google.com/g/django-developers/c/nDMnO98nexY/m/4fhLtlR7AwAJ) might provide a better alternative:

> Django 5.0 will hopefully come with generated fields: [https://github.com/django/django/pull/16417](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…
