gpt4 book ai didi

python - auth.User.groups : (fields. E304) 'User.groups' 的反向访问器与 'UserManage.groups' 的反向访问器冲突

转载 作者:IT老高 更新时间:2023-10-28 22:17:08 28 4
gpt4 key购买 nike

在我的 Django 项目中,我有一个 user_manage 应用程序。

我在 user_manage 应用的 model.py 中创建了一个名为 UserManage 的模型:

from django.db import models
from django.contrib.auth.models import AbstractUser

class UserManage(AbstractUser):
username = models.CharField(max_length=12)

然后我运行:

$ python3 manage.py makemigrations

出现错误:

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

最佳答案

将以下内容添加到 settings.py:

AUTH_USER_MODEL = "users_management.UserManage" 

更一般地说,

AUTH_USER_MODEL = 'YourAppName.YourClassName'
  • YourAppName:这是具有用户模型的应用的名称
  • YourClassName:这是 models.py 文件中使用的类的名称

关于python - auth.User.groups : (fields. E304) 'User.groups' 的反向访问器与 'UserManage.groups' 的反向访问器冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49189402/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com