作者:靈幻雪月 | 来源:互联网 | 2023-05-18 16:20
Imcreatingatableasfollows:我正在创建一个表如下:@OverridepublicvoidonCreate(SQLiteDatabasedb){
I'm creating a table as follows:
我正在创建一个表如下:
@Override
public void onCreate(SQLiteDatabase db) {
String sql =
"CREATE TABLE IF NOT EXISTS users (" +
"_id INTEGER PRIMARY KEY, " +
"name TEXT NOT NULL, " +
"password TEXT NOT NULL);";
db.execSQL(sql);
sql = "INSERT INTO users VALUES ('testuser', 'textpassword')";
db.execSQL(sql);
}
But when I try to insert a user, I'm getting the following exception:
但是当我尝试插入用户时,我遇到以下异常:
android.database.sqlite.SQLiteException: table users has 3 columns but 2 values were supplied (code 1): , while compiling: INSERT INTO users VALUES ('testuser', 'textpassword')
android.database.sqlite.SQLiteException:表用户有3列但提供了2个值(代码1):,同时编译:INSERT INTO用户VALUES('testuser','textpassword')
As _id
is the primarykey, why is it expecting it? I also tried AUTOINCREMENT
but it doesn't work.
由于_id是主键,它为什么期待它?我也试过AUTOINCREMENT但它不起作用。
2 个解决方案