码迷,mamicode.com
首页 > 其他好文 > 详细

bug之needs to have a value for field "id" before this many-to-many relationship can be used.

时间:2020-03-12 18:45:06      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:brief   span   str   clean   cts   before   ane   error:   div   

一、环境配置

  操作系统:WIndows 64

  django版本:3.0.3

  数据库:mysql

二、报错代码

c = Category()
c.name = cleaned_data.get("name")
c.brief = cleaned_data.get("brief")
c.author.add(User.objects.get(username=username))
c.save()
ValueError: "<Category: C++>" needs to have a value for field "id" before this many-to-many relationship can be used.

三、解决方法

c = Category()
c.name = cleaned_data.get("name")
c.brief = cleaned_data.get("brief")
c.save()
c.author.add(User.objects.get(username=username))
c.save()

 

bug之needs to have a value for field "id" before this many-to-many relationship can be used.

标签:brief   span   str   clean   cts   before   ane   error:   div   

原文地址:https://www.cnblogs.com/loveprogramme/p/12475352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!