我有一个正在运行的数据库,但主键不会自动递增。有谁知道是什么问题?
代码如下
// 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);";
答案 0 :(得分:3)
您必须创建主键
...."(" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT.....
您忘记了所有AUTOINCREMENT
关键字。