I have a custom User model with email as username. I have encrypted the email field to be in conformity with GPDR (I will hold a lot of personal information). I have added a email_hash field with index on it for the database to be able to retrieve immediately user. I have modified get_natural_key of my user object manager to use the hash for retrieve.
But now i face a problem I have to disable the uniqueness on field email (username field) but Django don't let me do it when i try to makemigrations.
myuser.MyUser: (auth.E003) 'MyUser.email' must be unique because it is named as the 'USERNAME_FIELD'.
Otherwise, I want the uniqueness error to be fired on email field and not on email_hash field ....
How to have functional encrypted email field as user and stored hash for index ?
edit:
I have disable uniqueness check on email field and added SILENCED_SYSTEM_CHECKS = ["auth.E003"]
in settings.
Now my problem is to have uniqueness error of email_hash rendered as email error to have "A user with that email address already exists." message displayed on correct forms and django rest framework serializer field.