0

Android SQLite ON UPDATE CASCADE not working
Please help me
These are my tables

    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 )"; 

1 Answers1

1

In this line you have set the foreign key to set null on deletes, rather than cascade:

"FOREIGN KEY(IDZ) REFERENCES ZONA(IDZ) on delete set null on update cascade,"

You should set it to on delete cascade. You might also need to recreate the tables for changes to apply (remove the IF NOT EXISTS condition).

zaadeh
  • 1,711
  • 2
  • 23
  • 37