其他分享
首页 > 其他分享> > django 中新建auth_user_model

django 中新建auth_user_model

作者:互联网

 

     在项目中不想使用django自带的用户管理系统,需要增加一些用户属性,我们可以这么做。

     在app的model.py 中继承AbstractUser创建自己的用户管理系统类 user_info

from django.contrib.auth.models import AbstractUser

class user_info(AbstractUser):
author = models.CharField(max_length=12)
login = models.BooleanField(default=False)

def __str__(self):
return self.username

         之后使用命令python manage.py makemigrations创建数据库表,碰到如下错误。

root@startbudd2:/home/zhj/lot/star_lot# python manage.py makemigrations
SystemCheckError: System check identified some issues:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'user_info.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'user_info.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'user_info.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'user_info.user_permissions'.
star_link.user_info.groups: (fields.E304) Reverse accessor for 'user_info.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'user_info.groups' or 'User.groups'.
star_link.user_info.user_permissions: (fields.E304) Reverse accessor for 'user_info.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'user_info.user_permissions' or 'User.user_permissions'.

       解决这个问题的方法:

       在本工程的setting.py 文件中添加:      

  AUTH_USER_MODEL = "star_link.user_info"

标签:info,auth,User,user,groups,model,accessor,permissions
来源: https://www.cnblogs.com/huanhuaqingfeng/p/11102192.html