Java Android SQLITE外键列为空
该项目包含两个表,一个是包含所有用户信息的Duser,另一个是测试表。我想将用户id作为测试表中的外键传递给Duser表中的主键。当我打开数据库时,外键列总是空的。我还使用pragrma启用了外键,我是否需要手动传递外键,或者SQLite会这样做?如果是手动操作,那么如何操作?请帮忙Java Android SQLITE外键列为空,java,android-sqlite,Java,Android Sqlite,该项目包含两个表,一个是包含所有用户信息的Duser,另一个是测试表。我想将用户id作为测试表中的外键传递给Duser表中的主键。当我打开数据库时,外键列总是空的。我还使用pragrma启用了外键,我是否需要手动传递外键,或者SQLite会这样做?如果是手动操作,那么如何操作?请帮忙 @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL("Create
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("Create Table Duser(id integer primary key autoincrement,email Text, name text,password text, confirm text, number string)");
sqLiteDatabase.execSQL("Create table test(Iid integer primary key autoincrement, name Text, f_id integer NOT NULL , Foreign key(f_id) REFERENCES DUSER(id) on update restrict on delete restrict)");
onConfigure(sqLiteDatabase);
}
当我打开数据库时,外键列总是空的,这段代码在哪里?
@Override
public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db);
db.execSQL("PRAGMA foreign_keys=ON;");
}
public boolean Insert(String email, String name, String password, String confirm, String number) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("email", email);
contentValues.put("name", name);
contentValues.put("password", password);
contentValues.put("confirm", confirm);
contentValues.put("number", number);
long ins = db.insert("Duser", "null", contentValues);
if (ins == -1)
return false;
else return true;
}
public boolean addInterest(String name) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
long ins = db.insert("test", null, contentValues);
if (ins == -1)
return false;
else return true;
}