python - IntegrityError when inserting model with composite primary key -
i trying create table composite primary keys. has 1 integer , 2 string fields key. when commit session raises integrityerror
. wrong doing?
class targets(db.model): __tablename__ = 'targets' id = db.column(db.integer, primary_key=true) event_name = db.column(db.string, index=true, default='single_trigger', primary_key=true) trigger_id = db.column(db.string, index=true, unique=true, primary_key=true) >>> app import db, models >>> target = models.targets(trigger_id='20150421_221942_st_1') >>> db.session.add(target) >>> db.session.commit() integrityerror: (integrityerror) not null constraint failed: targets.id u'insert "targets" ("event_name", "name", "trigger_id", "tile", "status", "ra", "dec", "filter", "exp_time", "no_exp") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ('single_trigger', '20150421_221942_st_1', '20150421_221942_st_1', 1, 0, 102.0, 231.25, 'v', 30, 5)
sqlalchemy doesn't set auto-increment on composite keys, need set autoincrement=true on id column.
if table has composite primary key consisting of more 1 integer column, set flag true on column should considered “autoincrement”.
Comments
Post a Comment