2016-05-13 2 views
0

У меня есть модель ниже и получение ошибки IntegrityError: NOT NULL constraint failed: terms.sets_id. Я проверил другие сообщения, и единственное, что могу найти, это должно быть причиной того, что я не передаю все параметры, но я объявляю пять полей и передаю 5 значений в concept = cls(...). Что мне не хватает?peewee IntegrityError: NOT NULL constraint failed: terms.sets_id

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") 

ответ

3

Вы просто неверно набрали свойства своего класса. В определении поля используется sets_id, тогда как метод include_term использует set_id. Следующий код, изменяемый для вашего кода, должен заставить его работать нормально.

class Terms(UserMixin, BaseModel): 
    term_id = CharField() 
    set_id = CharField() 
    term_count = IntegerField() 
    term = TextField() 
    definition = TextField() 
Смежные вопросы