Android SQLite ON UPDATE CASCADE无法正常工作
请帮帮我
这些是我的表
String tablausuariocreate="CREATE TABLE IF NOT EXISTS USUARIO(" +
"idusuario INTEGER PRIMARY KEY NOT NULL," +
"DELETED BOOLEAN DEFAULT(0))";
String tablazonacreate="CREATE TABLE IF NOT EXISTS ZONA(" +
"IDZ INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
"NAME VARCHAR(150)," +
"idusuario integer," +
"DELETED BOOLEAN DEFAULT(0)," +
"FOREIGN KEY(idusuario) REFERENCES USUARIO(idusuario) on update cascade)";
String tablaclientecreate = "CREATE TABLE IF NOT EXISTS CLIENTE(" +
"IDC INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
"NAME VARCHAR(50) UNIQUE," +
"IDZ INTEGER," +
"idusuario integer," +
"DELETED BOOLEAN DEFAULT(0)," +
"FOREIGN KEY(IDZ) REFERENCES ZONA(IDZ) on delete set null on update cascade," +
"FOREIGN KEY(idusuario) REFERENCES USUARIO(idusuario) on update cascade )";
答案 0 :(得分:1)
在这一行中,您设置了外键,在删除时设置为null,而不是级联:
"FOREIGN KEY(IDZ) REFERENCES ZONA(IDZ) on delete set null on update cascade,"
您应该将其设置为on delete cascade
。
您可能还需要重新创建要应用更改的表(删除IF NOT EXISTS
条件)。