Auto Increment on Composite Primary Key - Sqlite3 + Python -
i have code this
c.execute('create table if not exists base (id integer not null, col2 text not null, col3 integer, primary key(id, col2))')
this code gives me sqlite3.integrityerror exception though sure writing record first time.
so, tried
c.execute('create table if not exists base (id integer, col2 text, col3 integer, primary key(id, col2))')
this inserts row fine in base table but, id column not auto incremented @ all.
what can do? idea?
in sqlite, autoincrement behavior when 1 integer column primary key. composite keys prevent autoincrement taking effect.
you can similar result defining id
primary key, adding additional unique constraint on id, col3
.
if that's still not quite want (say, id's don't need unique @ all), have use trigger make autoincrement work.
Comments
Post a Comment