以下代码是我的数据库架构,运行onCreate
方法后,我收到此错误:
08-28 08:13:23.984 3214-3214/ir.tsms E/Database﹕ Failure 1 (table "ReceiveFields" has more than one primary key) on 0x1175f8 when preparing 'CREATE TABLE ReceiveFields(id INTEGER PRIMARY KEY AUTOINCREMENT, lastId INTEGER , smsNumber VARCHAR , mobileNumber VARCHAR , senderName VARCHAR , smsBody TEXT , receiveDate VARCHAR , PRIMARY KEY (id));'.
DataBase创建架构变量:
private static final String DATABASE_CREATE = "CREATE TABLE " + RECEIVE_FIELDS_TABLE + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COLUMN_LASTID + " INTEGER , "
+ COLUMN_SMSNUMBER + " VARCHAR , "
+ COLUMN_MOBILENUMBER + " VARCHAR , "
+ COLUMN_SENDERNAME + " VARCHAR , "
+ COLUMN_SMSBODY + " TEXT , "
+ COLUMN_RECEIVEDATE + " VARCHAR , PRIMARY KEY (" + COLUMN_ID + "));";
Log.i
DATABASE_CREATE
的结果:
CREATE TABLE ReceiveFields(
id INTEGER PRIMARY KEY AUTOINCREMENT,
lastId INTEGER ,
smsNumber VARCHAR ,
mobileNumber VARCHAR ,
senderName VARCHAR ,
smsBody TEXT ,
receiveDate VARCHAR ,
PRIMARY KEY (id)
);
我的创建表问题是什么?感谢
答案 0 :(得分:0)
从PRIMARY KEY (" + COLUMN_ID + ")
查询字符串的末尾删除DATABASE_CREATE
将您的代码更改为:
private static final String DATABASE_CREATE = "CREATE TABLE " + RECEIVE_FIELDS_TABLE + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COLUMN_LASTID + " INTEGER , "
+ COLUMN_SMSNUMBER + " VARCHAR , "
+ COLUMN_MOBILENUMBER + " VARCHAR , "
+ COLUMN_SENDERNAME + " VARCHAR , "
+ COLUMN_SMSBODY + " TEXT , "
+ COLUMN_RECEIVEDATE + " VARCHAR );";