简体   繁体   English

AttributeError: 类型对象“User”没有属性“USERNAME_FIELD”

[英]AttributeError: type object 'User' has no attribute 'USERNAME_FIELD'

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.我知道 User 类需要 USERNAME_FIELD,但我有这个,所以我不确定到底是什么问题。 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)

在 User 模型中添加 username=None 字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 类型对象“MyUser”没有属性“USERNAME_FIELD” - AttributeError: type object 'MyUser' has no attribute 'USERNAME_FIELD' (Django) 类型对象 'User' 没有属性 'USERNAME_FIELD' - (Django) type object 'User' has no attribute 'USERNAME_FIELD' Django 通过通用 USERNAME_FIELD 获取用户 - Django get user by generic USERNAME_FIELD 数据迁移导致错误 AttributeError: type object 'User' has no attribute 'normalize_username'? - Data migration causes error AttributeError: type object 'User' has no attribute 'normalize_username'? AttributeError: 类型对象“用户”没有属性“获取” - AttributeError: type object 'User' has no attribute 'get' AttributeError: 类型对象“用户”没有属性“查询” - AttributeError: type object 'User' has no attribute 'query' AttributeError-命名空间对象没有属性用户名 - AttributeError - Namespace object has no attribute username Django AttributeError:“ MyModel”对象没有属性“ username” - Django AttributeError: 'MyModel' object has no attribute 'username' AttributeError:'NoneType'对象没有属性'userName' - AttributeError: 'NoneType' object has no attribute 'userName' Django AttributeError 'CreateUserForm' object 没有属性 'username' - Django AttributeError 'CreateUserForm' object has no attribute 'username'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM