简体   繁体   中英

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. 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(...) . 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 . 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM