gpt4 book ai didi

python - peewee IntegrityError : NOT NULL constraint failed: terms.sets_id

转载 作者:行者123 更新时间:2023-11-30 22:55:57 24 4
gpt4 key购买 nike

我有以下模型并收到 IntegrityError: NOT NULL 约束失败: terms.sets_id 错误。我检查了其他帖子,我能找到的唯一原因是我没有传入所有参数,但我声明了五个字段,并将 5 个值传入 concept = cls(. ..)。我错过了什么?

class Terms(UserMixin, BaseModel):
term_id = CharField()
sets_id = CharField()
term_count = IntegerField()
term = TextField()
definition = TextField()

@classmethod
def include_term(cls, set_id, term_id, definition, rank, term, **kwards):
try:
cls.select().where(cls.term_id == term_id).get()
except cls.DoesNotExist:
print("putting term into db")
concept = cls(
set_id = set_id,
term_id = term_id,
term= term,
definition = definition,
rank = rank )
concept.save()
print(concept.term)
print("term saved to db")
return concept
else:
raise Exception("Term with that id already exists")

最佳答案

您只是错误地输入了类属性。您的字段定义使用 sets_id,而 include_term 方法使用 set_id。对您的代码进行以下代码更改应该可以使其正常工作。

class Terms(UserMixin, BaseModel):
term_id = CharField()
set_id = CharField()
term_count = IntegerField()
term = TextField()
definition = TextField()

关于python - peewee IntegrityError : NOT NULL constraint failed: terms.sets_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37201118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com