[英]peewee IntegrityError: NOT NULL constraint failed: terms.sets_id
I have the below model and getting a IntegrityError: NOT NULL constraint failed: terms.sets_id
error. 我有以下模型并获得IntegrityError: NOT NULL constraint failed: terms.sets_id
错误。 I've checked other posts and the only thing I can find that should be causing it is that I'm not passing in all the parameters, but I declare five fields, and pass in 5 values into concept = cls(...)
. 我已经检查了其他帖子,我唯一可以找到它应该导致它的是我没有传递所有参数,但我声明了五个字段,并传入5个值到concept = cls(...)
。 What am I missing? 我错过了什么?
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")
You've simply typed your class properties incorrectly. 您只是错误地键入了类属性。 Your field definition uses sets_id
while the include_term
method uses set_id
. 您的字段定义使用sets_id
而include_term
方法使用set_id
。 The following code change to your code should make it work fine. 以下代码更改为您的代码应使其正常工作。
class Terms(UserMixin, BaseModel):
term_id = CharField()
set_id = CharField()
term_count = IntegerField()
term = TextField()
definition = TextField()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.