Django Abstract User Error

若如初见. 提交于 2019-11-27 12:50:59

问题


I am working on extending the User class based on the docs with the code below:

from django.contrib.auth.models import AbstractUser

class MyUser(AbstractUser):
  some_extra_data = models.CharField(max_length=100, blank=True)

However, I'm returning the following error

Reverse accessor for 'User.groups' clashes with reverse accessor for 'MyUser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'MyUser.groups'.

I understand resolving this type of conflict by adding a related_name to FK. How would I resolve it in this scenario?


回答1:


You need to set your AUTH_USER_MODEL setting to point to your MyUser model, so that Django knows not to initialise the default model. See the documentation.




回答2:


Add this line

AUTH_USER_MODEL = "app_name.MyUser"

in the settings.py it works.



来源:https://stackoverflow.com/questions/26703323/django-abstract-user-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!