AttributeError: type object 'User' has no attribute 'USERNAME_FIELD'

Viewed 1229

This is my code. I understand that the User class needs USERNAME_FIELD, but I have that, so I am not sure exactly what the issue is. Any help is greatly appreciated.

# User model
class User(AbstractBaseUser):
    # email
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []
    # active status
    active = models.BooleanField(default=True)
    # admin status
    admin = models.BooleanField(default=False)
    # first name
    fname = models.TextField(default="")
    # last name
    lname = models.TextField(default="")
    # what year of graduation
    year = models.IntegerField(default = 0)

1 Answers

Add a username=None field in the User model.

Related