Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

python 3.x - SystemCheckError: System check identified some issues:

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

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

Traceback:

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

My models.py is as follows:

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add related_name like:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...