Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY - android

Tags:

People also ask

Is Autoincrement primary key?

Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.

What is integer primary key autoincrement?

Summary. The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed. In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID (except in WITHOUT ROWID tables) which is always a 64-bit signed integer.

How do I set Autoincrement value?

In MySQL, the syntax to change the starting value for an AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = start_value; table_name. The name of the table whose AUTO_INCREMENT value you wish to change.

What does Autoincrement mean?

Auto Increment is a field used to generate a unique number for every new record added into a table. This is generally used for the primary key column as it becomes easy for the developers to automatically generate a unique number for every new record.


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 only allowed on an INTEGER PRIMARY KEY

Here is my query:

@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 have also tried to write AUTO_INCREMENT but then I got syntax error.

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

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