Django syncdb error: One or more models did not validate

那年仲夏 提交于 2019-12-29 08:37:10

问题


/mysite/project4

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

Details and User are in the same module i.e,/mysite/project1 In project1 models i have defined

   class User():
      ......

   class Details():
      ......

When DB i synced there is an error saying

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

How can this be solved..

thanks..


回答1:


Gee we just had this one; and I answered...

You have a number of foreign keys which django is unable to generate unique names for.

You can help out by adding "related_name" arguments to the foreignkey field definitions in your models. Eg:

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

See here for more. http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name



来源:https://stackoverflow.com/questions/2608017/django-syncdb-error-one-or-more-models-did-not-validate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!