Skip to content Skip to sidebar Skip to footer

Autoincrement Is Only Allowed On An Integer Primary Key - Android

I'm trying to create a table in my DB with an ID that is autoincrement itself but whenever I try to add the AUTOINCREMENT keyword to my query it tells me that : AUTOINCREMENT is o

Solution 1:

You need to add a space between KEY_ID AND INTEGER

So change

+ KEY_ID + "INTEGER PRIMARY KEY AUTOINCREMENT, "

to

+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "

Solution 2:

Create table with integer primary key no need to explicitly mention the AUTOINCREMENT

e.g.

CREATETABLE t1(
  a INTEGERPRIMARY KEY,
  C TEXT
); 

Insertinto t1(C) values("Hello");

Solution 3:

Create Table like this put some space before INTEGER ....

"CREATE TABLE "+TABLE_NAME+" ("+KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT)";

Post a Comment for "Autoincrement Is Only Allowed On An Integer Primary Key - Android"