gpt4 book ai didi

Android On Delete Cascade 无法正常工作

转载 作者:太空狗 更新时间:2023-10-29 16:42:06 28 4
gpt4 key购买 nike

我正在制作 android 应用程序,其中我在一个开放的帮助程序类中制作了 5 个表。当我在我的模式中有 ON DELETE CASCADE 时,我遇到了问题。我知道 ON DELETE CASCADE 的概念。在这里,我正在复制我的两个表中的一个。

private static final String MEDICINE_TABLE  = "create table medicine_details (_mid integer primary key autoincrement, "
+ " medicine_name text, type text, take_with text, m_did integer not null,"
+ "FOREIGN KEY(m_did) REFERENCES doctor_details(did)"
+ " ON DELETE CASCADE" + ");";

private static final String SCH_TAB = "CREATE TABLE schedule_details(sid INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "medi_stdate TEXT,medi_end_date TEXT,time_sch TEXT,rept TEXT, alarm_id NUMBER, "
+ "u_id integer not null, doc_id integer not null, mid integer not null, "
+ "FOREIGN KEY(u_id) REFERENCES member_details(_id)"
+ " ON DELETE CASCADE,"
+ "FOREIGN KEY(doc_id) REFERENCES doctor_details(did)"
+ " ON DELETE CASCADE,"
+ "FOREIGN KEY(mid) REFERENCES medicine_details(_mid)"
+ " ON DELETE CASCADE" + ");";

每当我尝试从医学中删除时,它只会从医学表中删除,而不是从时间表中删除。这里 medicine table 是 master table,schedule table 是 child table。

最佳答案

您必须覆盖 open() 方法,如下例所示:

    @Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=ON;");
}
}

最好的问候

关于Android On Delete Cascade 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16080564/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com