SqliteConstraintException に問題があります。私のデータベースはそのようなものです
private static final String CREATE_TABLE_1 =
"create table table_1 (uid integer primary key autoincrement, "
+ table_1.c1 + " TEXT,"
+ table_1.c2 + " integer,"
+ table_1.c3 + " TEXT,"
+ table_1.c4 + " TEXT,"
+ table_1.c5 + " integer);";
private static final String CREATE_TABLE_2 =
"create table table_2 (uid integer primary key autoincrement, "
+ table_2.c1 + " TEXT,"
+ table_2.c2 + " integer,"
+ table_2.c3 + " TEXT);";
private static final String CREATE_TABLE_3 =
"create table table_3 (uid integer primary key autoincrement, "
+ "uid_table_1 integer, "
+ "uid_table_2 integer, "
+ "FOREIGN KEY(uid_table_1) REFERENCES table_1(uid) ON DELETE CASCADE, "
+ "FOREIGN KEY(uid_table_2) REFERENCES table_2(uid) ON DELETE CASCADE);";
private static final String CREATE_TABLE_4 =
"create table table_4 (uid integer primary key autoincrement, "
+ "uid_table_2 integer,"
+ "FOREIGN KEY(uid_table_2) REFERENCES table_2(uid) ON DELETE CASCADE);";
そして、SQLiteOpenHelperで使用して、外部キー制約を有効にします
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
// Enable foreign key constraints
db.execSQL("PRAGMA foreign_keys=ON;");
}
しかし、table_2 の行を削除しようとすると、SqliteConstraintException が発生します。私を助けてくれませんか?
ありがとうございました