andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

the foreign key field accept values that doesn't exist #478

Open Nouhack opened 3 years ago

Nouhack commented 3 years ago
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.
AdnanAshraf7 commented 2 years ago

have you got any solution ?

Nouhack commented 2 years ago

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.

AdnanAshraf-pro commented 2 years ago

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