Django Reverse accessor error

不问归期 提交于 2019-12-21 17:53:42

问题


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'.

回答1:


You need to add AUTH_USER_MODEL to your setting.py file. Django needs to know that to initialise the default model. 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




回答2:


is using AbstractUser, then you should use into file settings.py:

AUTH_USER_MODEL = 'user.user'


来源:https://stackoverflow.com/questions/40843365/django-reverse-accessor-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!