Android table creation Failure (near “autoincrement”: syntax error)?

In short: In SQLite a column declared INTEGER PRIMARY KEY will autoincrement. There is no autoincrement keyword in SQLite, that is why you are getting an error.

You can find out more on SQLite FAQ.

EDIT: just writing integer primary key it is enough. SQLite will automatically increment your ids.

EDIT2: Your onUpgrade() method should look like this :

  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion > oldVersion) {
            Log.w("MyAppTag","Updating database from version " + oldVersion + " to "
                    + newVersion + " .Existing data will be lost.");
            db.execSQL("DROP TABLE IF EXISTS " + MY_TABLE);
            db.execSQL("DROP TABLE IF EXISTS " + MY_TABLE2);
            onCreate(db);
        }

Leave a Comment