Hello everyone. In my application the login is done by email and not by a username. Is it advisable to create a custom model of the User model or is it possible to just copy the email field to the username?
Because currently the username field is empty and I get the following console output:
django.db.utils.IntegrityError: UNIQUE constraint failed: auth_user.username
Which I understand that I get it because when the first user registers, the username field is left blank.
Is it advisable to copy what goes in the email field in the username field?
Sure - that’s one way to do it.
There’s no “right” or “wrong” here - it’s an architectural decision that should be made in the context of the overall requirements for the system.
If you’re not willing to use the
username field, you can remove it.
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
class YourUserModel(PermissionsMixin, AbstractBaseUser):
username = None
# Your other fields
That is another way to do it, but then he’s no longer using the standard default User model.