简体   繁体   English

peewee IntegrityError:NOT NULL约束失败:terms.sets_id

[英]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_idinclude_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.

相关问题 peewee.IntegrityError:NOT NULL约束失败 - peewee.IntegrityError: NOT NULL constraint failed 如何修复“ peewee.IntegrityError:NOT NULL约束失败:fiskalna.user_id” - How to fix “peewee.IntegrityError: NOT NULL constraint failed: fiskalna.user_id” IntegrityError NOT NULL约束失败 - IntegrityError NOT NULL constraint failed IntegrityError:NOT NULL 约束失败: - IntegrityError: NOT NULL constraint failed: peewee IntegrityError:唯一约束失败:userpost.user_id,userpost.post_id - peewee IntegrityError: UNIQUE constraint failed: userpost.user_id, userpost.post_id Django IntegrityError NOT Null约束失败reqs_student.section_id - Django IntegrityError NOT Null Constraint Failed reqs_student.section_id /profile NOT NULL 约束处的 IntegrityError 失败:tutorapp_profile.user_id - IntegrityError at /profile NOT NULL constraint failed: tutorapp_profile.user_id IntegrityError at /create/ NOT NULL 约束失败:main_post.author_id - IntegrityError at /create/ NOT NULL constraint failed: main_post.author_id /add/ NOT NULL 约束的 IntegrityError 失败:myApp_bookdetail.manager_id - IntegrityError at /add/ NOT NULL constraint failed: myApp_bookdetail.manager_id sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL 约束失败:user.id - sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: user.id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM