from django.db import models
from django.contrib.auth.models import AbstractUser
class Customer(AbstractUser):
address_line = models.CharField(max_length=255)
city = models.CharField(max_length=255)
postal_code = models.CharField(max_length=10)
phone_number = models.CharField(max_length=20)
origin_country = models.CharField(max_length=255)
profile_picture = models.ImageField(upload_to='customer_profile_pics', null=True, blank=True)
class Chef(AbstractUser):
address_line = models.CharField(max_length=255)
city = models.CharField(max_length=255)
postal_code = models.CharField(max_length=10)
phone_number = models.CharField(max_length=20)
origin_country = models.CharField(max_length=255)
profile_picture = models.ImageField(upload_to='chef_profile_pics', null=True, blank=True)
class Meal(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
picture = models.ImageField(upload_to='meal_pics')
country = models.CharField(max_length=255)
chef = models.ForeignKey(Chef, on_delete=models.CASCADE, related_name='meals')
customers = models.ManyToManyField(Customer, blank=True, related_name='meals')
class Discussion(models.Model):
message = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE, null=True, blank=True, related_name='discussions')
chef = models.ForeignKey(Chef, on_delete=models.CASCADE, null=True, blank=True, related_name='discussions')
这是我的models.py
文件,在进行迁移时出现以下错误
SystemCheckError: System check identified some issues:
ERRORS:
meals.Chef.groups: (fields.E304) Reverse accessor for 'Chef.groups' clashes with reverse accessor for 'Customer.groups'.
HINT: Add or change a related_name argument to the definition for 'Chef.groups' or 'Customer.groups'.
meals.Chef.user_permissions: (fields.E304) Reverse accessor for 'Chef.user_permissions' clashes with reverse accessor for 'Customer.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'Chef.user_permissions' or 'Customer.user_permissions'.
meals.Customer.groups: (fields.E304) Reverse accessor for 'Customer.groups' clashes with reverse accessor for 'Chef.groups'.
HINT: Add or change a related_name argument to the definition for 'Customer.groups' or 'Chef.groups'.
meals.Customer.user_permissions: (fields.E304) Reverse accessor for 'Customer.user_permissions' clashes with reverse accessor for 'Chef.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'Customer.user_permissions' or 'Chef.user_permissions'.
我尝试了一些解决方案在互联网上,但它没有工作,我想测试我的浏览器上的应用程序,但使迁移不断显示我这个错误,请帮助!!!
我真的是Django后端开发的新手,我试着解决这个问题,但我做不到。
1条答案
按热度按时间y1aodyip1#
为什么要创建两个用户模型?使用相同的字段?
AbstractUser
是用来定义用于验证的自定义模型。您确定您已经理解了吗?为了解决您的问题,您必须覆盖Abstract user中的
user_permissions
和groups
,以便重新定义此字段的related_name ...