Auto Increment on Composite Primary Key – Sqlite3 + Python

In sqlite, you only get autoincrement behavior when only one integer column is the primary key. composite keys prevent autoincrement from taking effect.

You can get a similar result by defining id as the only primary key, but then adding an additional unique constraint on id, col3.

If that’s still not quite what you want (say, id’s don’t need to be unique at all), you probably will have to use a trigger to make autoincrement work.

Leave a Comment