1

我有一个正在运行的数据库,但主键不会自动递增。有谁知道是什么问题?

代码如下

    // 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);";
4

1 回答 1

4

您必须像这样创建主键

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

您忘记了AUTOINCREMENT关键字,仅此而已。

于 2013-10-06T13:14:45.847 回答