学写博客网站后台,设计数据库结构时,博客(Article)表中定义了一个作者外键。
author=models.ForeignKey(settings.AUTH_USER_MODEL,verbose_name='作者')
这个外键是网站注册用户,这样用户也可以有发文权限,考虑到以后会扩展用户功能,创建了一个用户app(user),并在models.py编写了个用户模型(Ouser),结果migrate数据到数据库时遇到的以下错误。
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'Ouser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'Ouser.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'Ouser.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'Ouser.user_permissions'.
user.Ouser.groups: (fields.E304) Reverse accessor for 'Ouser.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'Ouser.groups' or 'User.groups'.
user.Ouser.user_permissions: (fields.E304) Reverse accessor for 'Ouser.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'Ouser.user_permissions' or 'User.user_permissions'.
解决方案:
在settings.py中加入
AUTH_USER_MODEL ="user.Ouser"
其中user为app名,Ouser为模型名。
另有一种解决方案,以及原理可参考https://blog.csdn.net/shishui07/article/details/79854163