Django模型错误 - "TypeError:'xxx'是此函数的无效关键字参数

Rik*_*iku 9 python django django-models

我收到错误:

TypeError: 'person' is an invalid keyword argument for this function
Run Code Online (Sandbox Code Playgroud)

我的模型是:

class Investment(models.Model):
company = models.ManyToManyField("Company", related_name ="Investments_company")
financial_org = models.ManyToManyField("Financial_org", related_name ="Investments_financial_org")
person = models.ManyToManyField("Person", related_name ="Investments_person")
Run Code Online (Sandbox Code Playgroud)

我的测试(给出错误):

investment1 = Investment(company = [], financial_org = financial1, person = [])
Run Code Online (Sandbox Code Playgroud)

jpi*_*pic 27

  1. 实现你的模型没有多少,investment1 = Investment()

  2. 保存你的模特,investment1.save()

  3. 添加很多很多,有几种方法可以investment1.person.add(person_model)或那样investment1.person.create(name='foo')

在保存模型之前,您可能不会使用ManyToMany关系,这是因为ManyToMany关系表中的行需要关系两侧的模型的pk.