SystemCheckError:系统检查确定了一些问题: [英] SystemCheckError: System check identified some issues:

查看:83
本文介绍了SystemCheckError:系统检查确定了一些问题:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个要下订单的项目.当我运行makemigrations命令时,它给出了一个错误

I am building a project to place an order. When I run makemigrations command then it gives an error of

SystemCheckError:系统检查发现了一些问题,我已从迁移中删除了迁移文件

SystemCheckError: System check identified some issues and I have deleted the migration file from migrations

跟踪:

order.Order.price :(字段E304)"Order.price"的反向访问器与"Order.product"的反向访问器冲突.
order.Order.price: (fields.E304) Reverse accessor for 'Order.price' clashes with reverse accessor for 'Order.product'.
  HINT: Add or change a related_name argument to the definition for 'Order.price' or 'Order.product'.

order.Order.product :(字段E304)"Order.product"的反向访问器与的反向访问器冲突订单价格".

order.Order.product: (fields.E304) Reverse accessor for 'Order.product' clashes with reverse accessor for 'Order.price'.

    HINT: Add or change a related_name argument to the definition for 'Order.product' or 'Order.price'.

我的 models.py 如下:

class Order(models.Model):
    company = models.ForeignKey(Company, on_delete=models.CASCADE)
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    price = models.ForeignKey(Product, on_delete=models.CASCADE)

    def __str__(self):
        return self.company + self.product + self.price

推荐答案

添加 related_name ,例如:

    company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name='company')
    product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='product')
    price = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='price')

related_name 用于链接模型.特别是,当您有多个 1 模型链接到另一个模型时.与您的情况一样,它是强制性的.参见_this_answer 以正确了解有关 related_name 的使用.

related_name is used to link the models. Especially, when you have more than 1 model linking to another model. It is compulsary as in your case. See_this_answer to understand properly about use of related_name.

这篇关于SystemCheckError:系统检查确定了一些问题:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆