I want to create a column of AUTOINCREMENT values in android. I tried the below way of doing it but it failed. I want the column to auto increment itself whenever a new record is added.
I get an exception “Can’t upgrade read-only database from version 0 to 25” when i include “AUTOINCREMENT” to game_id.
db.execSQL("CREATE TABLE Games (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"game_id INTEGER **AUTOINCREMENT**," +
"title TEXT" +
");");
In SQLite, the autoincrement keyword only modifies the behavior of the algorithm that selects the next null integer primary key. It does not behave in the manner you desire. Sorry.
The only solution I can come up with is to do what you want programatically and add the unique constraint to the game_id field
See Documentation Here
This worked in sqlite3, but you should try to catch the error if you enter something that is already in the table. The other possibility, depending on what you are after, is to create another table.