我正在用Django编写一个自定义用户模型,从
AbstractUser
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
redditauth.RedditUser.username: (models.E006) The field 'username' clashes with the field 'username' from model 'redditauth.reddituser'.
这是我为自定义用户模型编写的代码。
class RedditUser(AbstractUser):
username = models.CharField(unique=True, primary_key=True, validators=[validate_reddit_username], max_length=20)
token = models.CharField(max_length=256)
USERNAME_FIELD = username
REQUIRED_FIELDS = ['token']
def reddit(self):
with open('secret.json', 'r') as f:
secret = json.load(f)
return praw.Reddit(client_id=secret['client_id'], client_secret=secret['client_secret'],
refresh_token=self.token, user_agent='Plan-Reddit by /u/SkullTech101')
我尝试将其重命名为其他名称,而不是
username
,认为可能已经有字段名为
用户名
在里面
抽象用户
,但这并没有解决问题。