![](/img/trans.png)
[英]AttributeError: type object 'MyUser' has no attribute 'USERNAME_FIELD'
[英]AttributeError: type object 'User' has no attribute 'USERNAME_FIELD'
這是我的代碼。 我知道 User 類需要 USERNAME_FIELD,但我有這個,所以我不確定到底是什么問題。 任何幫助是極大的贊賞。
# 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.