Skip to content Skip to sidebar Skip to footer

Foreign Key Constraint On Delete Cascade Not Working In Sqlite Database On Android

I have 'days' table created as follows 'create table days(' + 'day_id integer primary key autoincrement, ' + 'conference_id integer , ' + 'day_

Solution 1:

Cascading delete isn't supported until Sqlite version 3.6.19, which is first included on Android 2.2.

Fortunately there is an alternative.

You can execute another query like this below your create table query:

db.execSQL("CREATE TRIGGER delete_days_with track BEFORE DELETE ON track "
       +  "FOR EACH ROW BEGIN"
       +         " DELETE FROM days WHERE track.day_id = days.day_id "
       +  "END;");

Note that delete_days_with_track is just a name descriptive of what the trigger does, and this is just the pattern I use; I believe you could name it anything you wish.

Solution 2:

According to the SQLite Documentation support for Foreign Keys was not added until 3.6.19.

Using 3.5.9 you'll have to do your cascade deletions in some other manner.

Post a Comment for "Foreign Key Constraint On Delete Cascade Not Working In Sqlite Database On Android"