Like many others, I'm trying to configure my Django app to use the email as the username field. I have some existing user accounts that I migrated to a custom user model successfully, though right now the custom model is identical to the Django user model:
# accounts/models.py
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
Anytime I try to set the USERNAME_FIELD
to email
, I get an error that the USERNAME_FIELD
cannot be included in REQUIRED_FIELDS
, as well as the error that it must be unique. (side note: email isn't required for the base User, so I don't understand the first error)
Is there any way to get this functionality while subclassing AbstractUser?
Or do I just need to subclass AbstractBaseUser
and specify every field, in the manner of this example?
If it's the latter, how would I go about making sure I define the exact same fields as the Django User model? I don't want to lose the users I have or cause issues with mismatched fields.
It seems silly to have to go all the way to fully specifying a custom model just to use an email address as the username, so maybe I'm missing something here. If there was a way to ensure unique fields in the Django User model, I don't think this would be an issue.