Django error message “Add a related_name argument to the definition”

前端 未结 8 1488
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 00:53
D:\\zjm_code\\basic_project>python manage.py syncdb
Error: One or more models did not validate:
topics.topic: Accessor for field \'content_type\' clashes with rel         


        
8条回答
  •  孤城傲影
    2020-12-01 01:08

    I had a similar problem when I was trying to code a solution for a table that would pull names of football teams from the same table. My table looked like this:

    hometeamID = models.ForeignKey(Team, null=False, on_delete=models.CASCADE)
    awayteamID = models.ForeignKey(Team, null=False, on_delete=models.CASCADE)
    

    making the below changes solved my issue:

    hometeamID = models.ForeignKey(Team, null=False, on_delete=models.CASCADE,related_name='home_team')
    awayteamID = models.ForeignKey(Team, null=False, on_delete=models.CASCADE,related_name='away_team')
    

提交回复
热议问题