react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

the foreign key field accept values that doesn't exist

Open Nouhack opened this issue 4 years ago • 3 comments

i created 3 tables test , images , services and all things were good . the table images has a foreign key : "CREATE TABLE IF NOT EXISTS images (ID INTEGER PRIMARY KEY AUTOINCREMENT , ID_TEST INTEGER , FOREIGN KEY (ID_TEST) REFERENCES test(ID))"

when i try to insert a new record ID_TEST field accepts everything even if the value given doesn't exist as ID to test table.

Nouhack avatar Jun 26 '21 00:06 Nouhack

have you got any solution ?

AdnanAshraf7 avatar Sep 30 '21 12:09 AdnanAshraf7

it's been a while since i posted this issue and i didn't find any solution , so i went with another solution where i used another package called react native sqlite2 and the problem was solved.

Nouhack avatar Sep 30 '21 16:09 Nouhack

db.executeSql('PRAGMA foreign_keys = ON'); Execute this after creating connection and it will solve your issue .. it worked for me.

AdnanAshraf-pro avatar Oct 05 '21 06:10 AdnanAshraf-pro