If you are using PostgreSQL I'd suggest using a CIText field[0] with a 
unique
constraint[1].
If you are *not* using PostgreSQL your best choice is likely to emulate the
upcoming expression[3] support for UniqueConstraint(Lower('field')) by using
a RunSQL operation that performs the appropriate DDL assuming your backend
supports it.

Best,
Simon

[0] 
https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#citext-fields
[1] https://docs.djangoproject.com/en/3.0/ref/models/fields/#unique
[3] https://github.com/django/django/pull/11929

Le jeudi 23 janvier 2020 21:36:29 UTC-5, Mike Dewhirst a écrit :
>
> What is the best way to ensure a charfield is case-insensitively unique? 
>
> Currently I'm using a query with __iexact=True but I wonder whether 
> there is a better way. 
>
> Thanks 
>
> Mike 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/967c8a27-a8ec-42fc-abf5-bda76fbb5ef9%40googlegroups.com.

Reply via email to