Q:

Android On Delete Cascade not working properly

I am making android app in which i make 5 tables in one open helper class. i am facing the problem while i am having ON DELETE CASCADE in my schema. i know the concept of ON DELETE CASCADE. here i am copy my one of two tables.
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" + ");";

whenever i try to delete from medicine,it deletes only from medicine table not from schedule table. here medicine table is a master table and schedule table is child table.

A:

you must override the method open() as you can see in the following example:
    @Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}

best regards

