[英]Django Reverse accessor error
I dont understand why some fields of my models clash. 我不明白为什么我的模特的某些领域会发生冲突。
I dont have any foreign key so why would they clash ?! 我没有任何外键,为什么他们会发生冲突?!
Here is my code: 这是我的代码:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import AbstractUser
import datetime
import uuid
# Create your models here
class Patients(AbstractUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
first_name = models.CharField(max_length = 255)
last_name = models.CharField(max_length = 255)
dob = models.DateField(datetime.date.today)
gender = models.CharField(max_length = 1)
def __unicode__(self):
return self.id
Here is the error: 这是错误:
api.Patients.groups: (fields.E304) Reverse accessor for 'Patients.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'Patients.groups' or 'User.groups'.
api.Patients.user_permissions: (fields.E304) Reverse accessor for 'Patients.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'Patients.user_permissions' or 'User.user_permissions'.
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'Patients.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'Patients.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'Patients.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'Patients.user_permissions'.
You need to add AUTH_USER_MODEL
to your setting.py
file. 您需要将
AUTH_USER_MODEL
添加到您的setting.py
文件中。 Django needs to know that to initialise the default model. Django需要知道初始化默认模型。 You can add that as follows:
您可以按如下方式添加:
AUTH_USER_MODEL = 'your_app.Patients'
Check this in the documentation Substituting a custom User model 替换文档替换自定义用户模型
Reference: https://stackoverflow.com/a/26703434/4575071 参考: https : //stackoverflow.com/a/26703434/4575071
正在使用AbstractUser,那么你应该使用到文件settings.py:
AUTH_USER_MODEL = 'user.user'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.