2

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")
Rafa
  • 3,219
  • 4
  • 38
  • 70

1 Answers1

4

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()
wyattis
  • 1,287
  • 10
  • 21