Skip to content
Advertisement

Add an autoincrementing ID column to an existing table with Sqlite

Using Sqlite, I want to add an auto-incrementing ID column to an existing table which had previously no ID:

How to do it properly? I have this error:

sqlite3.OperationalError: near “auto_increment”: syntax error

Advertisement

Answer

An SQLite table cannot modified in a significant manner using alter table once it has been created. One common popular suggestion is to create a new table with the existing fields as well as the additionally required field and copy/import your data into the new one and optionally delete the old one.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement