我创建了一些表:
"CREATE TABLE IF NOT EXISTS WORKOUTPLANS (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE, DESCRIPTION TEXT NOT NULL UNIQUE)";
"CREATE TABLE IF NOT EXISTS ENTITY (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE , DESCRIPTION TEXT NOT NULL UNIQUE)";
"CREATE TABLE IF NOT EXISTS EXERCISE (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE , DESCRIPTION TEXT NOT NULL UNIQUE , REPS TEXT NOT NULL , WEIGHT TEXT NOT NULL)";
"CREATE TABLE IF NOT EXISTS WPEN (PLANID, ENID, FOREIGN KEY(PLANID) REFERENCES WORKOUTPLANS(ID) ON DELETE CASCADE, FOREIGN KEY(ENID) REFERENCES ENTITY(ID) ON DELETE CASCADE)";
"CREATE TABLE IF NOT EXISTS ENEX (ENTITYID, EXERCISEID, FOREIGN KEY(ENTITYID) REFERENCES ENTITY(ID) ON DELETE CASCADE, FOREIGN KEY(EXERCISEID) REFERENCES EXERCISE(ID) ON DELETE CASCADE)";
如您所见,我必须有 m:n 关系,并且在这个连接表中,我对删除级联有约束。我知道每次连接到数据库时我都必须在 sqlite 中激活外键,我也是如此。
但是,当我删除 WORKOUTPLANS 中的一行时,它只是删除了 WORKOUTPLANS 和 WPEN 中的行,而不是 ENTITY、EXERCISE 和 ENEX 中的行
为什么 on delete 级联不起作用?