当前位置:   article > 正文

ValueError问题的解决_valueerror: an event handler (nulister) didn't rec

valueerror: an event handler (nulister) didn't receive enough input values (
博客Entry和作者Author之间定义成了多对多的关系,Model类Entry中有 authors = models.ManyToManyField(Author)
在添加博客记录时设置多对多的关系,出现了问题:


ValueError:"<Entry:django the newest techology>" need to have a value for field 'id' before this many-to-many relationship can be used


因为entry没有被写入到数据库,访问它的authors属性会有问题


解决办法:
先设置好Entry对象的其他非空属性,并保存,再设置多对多关系:
entry = Entry()
entry.headline = 'headline'
entry.body_text = "body text"
...
entry.save()
entry.authors.add(author)

entry.save()



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/865935
推荐阅读
相关标签
  

闽ICP备14008679号