一尘不染

Django syncdb错误:一个或多个模型未验证

python

/ mysite / project4

 class notes(models.Model):
   created_by = models.ForeignKey(User)
   detail = models.ForeignKey(Details)

详细信息和用户位于同一模块中,即/ mysite / project1在我定义的project1模型中

   class User():
      ......

   class Details():
      ......

当我同步数据库时,出现错误提示

Error: One or more models did not validate: project4: Accessor for field 'detail' clashes with related field . Add a related_name argument to the definition for 'detail'.

这怎么解决..

谢谢..


阅读 140

收藏
2021-01-20

共1个答案

一尘不染

哎呀,我们只有这个。我回答…

您有许多django无法为其生成唯一名称的外键。

您可以通过在模型中的外键字段定义中添加“ related_name”参数来提供帮助。例如:

 class notes(models.Model):
    created_by = models.ForeignKey(User, related_name="note_created_by_user")
    detail = models.ForeignKey(Details, related_name="noted_and_detailed")

看到这里更多。http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name

2021-01-20