一、环境配置

  操作系统: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()

 

相关文章:

  • 2021-06-24
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-11-16
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2022-01-12
  • 2022-02-17
  • 2021-10-01
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案