Auto Increment not working in android SQLite Database

送分小仙女□ 提交于 2019-12-11 05:38:35

问题


I've got a running database but the primary key won't auto increment. Does anyone know what the problem could be?

The code is as following

    // Database name and Version
private static final String DATABASE_NAME = "kmky_database.db";
private static final int DATABASE_VERSION = 1;

// Database Table
private static final String TABLE_NAME = "logs";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_PHONENUMBER = "phonenumber";
private static final String COLUMN_TYPE = "type";
private static final String COLUMN_DATE = "timestamp";
private static final String COLUMN_INCOMING = "incoming";
private static final String COLUMN_OUTGOING = "outgoing";
private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME + "(" + COLUMN_ID + " INTEGER PRIMARY KEY, " + COLUMN_PHONENUMBER + " TEXT, " + COLUMN_TYPE + " TEXT, " + COLUMN_DATE + " INTEGER, " + COLUMN_INCOMING + " INTEGER, " + COLUMN_OUTGOING + " INTEGER);";

回答1:


You have to create the Primary key as this

  ...."(" + COLUMN_ID + "  INTEGER PRIMARY KEY AUTOINCREMENT.....

You forgot the AUTOINCREMENT key word thats all.



来源:https://stackoverflow.com/questions/19209222/auto-increment-not-working-in-android-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!