2016-05-13 38 views
0

私は以下のモデルを持っており、IntegrityError: NOT NULL constraint failed: terms.sets_idエラーが発生しています。私は他の投稿をチェックしましたが、私はすべてのパラメータを渡すわけではありませんが、5つのフィールドを宣言して、5つの値をconcept = cls(...)に渡すことが原因であるはずです。私は何が欠けていますか?peewee IntegrityError:NOT NULL制約に失敗しました: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() 
関連する問題