简体   繁体   中英

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

正在使用AbstractUser,那么你应该使用到文件settings.py:

AUTH_USER_MODEL = 'user.user'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM