AUTOINCREMENT is only allowed on INTEGER PRIMARY KEY - android

I am trying to create a table in my DB with an identifier that is auto-incrementing itself, but whenever I try to add the AUTOINCREMENT keyword to my query, it tells me that:

AUTOINCREMENT is only allowed in INTEGER BASIC KEY

Here is my request:

@Override public void onCreate(SQLiteDatabase db) { String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_TASKS + " ( " + KEY_ID + "INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NOTETITLE + " TEXT, " + KEY_NOTECONTENT + " Text, " + KEY_STATUS + " INTEGER)"; db.execSQL(sql); } 

I also tried writing AUTO_INCREMENT, but then received a syntax error.

I found out that this is the source of the problem, because whenever I try to delete the word AUTOINCREMENT, it works fine.

So ... what do you think is the problem?

+6
source share
3 answers

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, " 
+18
source

Create a table with an integer primary key, no need to explicitly specify AUTOINCREMENT

eg.

 CREATE TABLE t1( a INTEGER PRIMARY KEY, C TEXT ); Insert into t1(C) values("Hello"); 
+4
source

Creating a table like this puts some space in front of INTEGER ....

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

Source: https://habr.com/ru/post/974530/


All Articles