Skip to content Skip to sidebar Skip to footer

Android: Inserting Sqlite Record With Autoincrement Column

I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE criterion ('_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, active text, important text, so

Solution 1:

Remove the NOT NULL from the schema and you're golden.

Clarifying: Specifying NOT NULL on an auto-increment column makes it so the auto-increment doesn't function. The NOT NULL is what is making it so you have to specify the _id.

Once you remove it, and don't include the _id in the insert statement, SQL will receive the _id as NULL and automatically handle setting the _id for you.

Post a Comment for "Android: Inserting Sqlite Record With Autoincrement Column"