I want to use an email field as the username field for my custom user model. I have the following custom User model subclassing Django's AbstractUser model:
class CustomUser(AbstractUser):
....
email = models.EmailField(max_length=255, unique=True)
USERNAME_FIELD = 'email'
But when I run
python manage.py sql myapp
I get the following error:
FieldError: Local field 'email' in class 'CustomUser' clashes with field of similar name from base class 'AbstractUser'
The reason I include my own email field in the first place is to add the unique=True
option to it. otherwise I get:
myapp.customuser: The USERNAME_FIELD must be unique. Add unique=True to the field parameters.
Now, in respect to this:
https://docs.djangoproject.com/en/1.5/topics/db/models/#field-name-hiding-is-not-permitted
How can I achieve this? (other then naming the field "user_email" or something like that instead)