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

Posted loveprogramme

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bug之needs to have a value for field "id" before this many-to-many relationship can be used相关的知识,希望对你有一定的参考价值。

一、环境配置

  操作系统: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的主要内容,如果未能解决你的问题,请参考以下文章

kafkaThe group member needs to have a valid member id before actually entering a consumer group(代码片段

You need to run build with JDK or have tools.jar问题解决

Server-side activities have been updated. You need to restart SharePoint Designer to use the updated

need do sth.和need to do sth.有啥区别?

The file is absent or does not have execute permission This file is needed to run this program

ex14 Python运行提示错误need more than 1 value to unpack