我不明白为什么我模特的某些领域会发生冲突。
我没有任何外键,为什么他们会发生冲突?!
这是我的代码:
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
这是错误:
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'.
答案 0 :(得分:10)
您需要将AUTH_USER_MODEL
添加到setting.py
文件中。 Django需要知道初始化默认模型。您可以按如下方式添加:
AUTH_USER_MODEL = 'your_app.Patients'
中查看此内容
答案 1 :(得分:0)
正在使用AbstractUser,那么您应该将其用于文件settings.py:
AUTH_USER_MODEL = 'user.user'