I'm writing a custom User model in Django, inheriting it from AbstractUser
as is mentioned in the official Django tutorials. But this throws an error.
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'.
Here is the code I wrote for the custom user model.
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')
I have tried renaming it to something other than username
, thinking that maybe there was already field named username
in AbstractUser
, but that didn't solve the problem.
As @Alasdair pointed out, I had to use a string, not a variable, when setting the value of USERNAME_FIELD
.
So in my case it was
USERNAME_FIELD = 'username'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments