Search notes:

SQLite: pragma foreign_keys

pragma foreign_keys = on enforces foreign keys. This is usually necessary because by default, SQLite does not enforce foreign keys.
Apparently, within a transaction, pragma foreign_keys remains without effect:
create table parent (
  id primary key
);

create table child (
  id_parent references parent
);

-- Ok:
insert into child values (1);

begin transaction;
--
--    Pragma foreign_keys is apparently without effect in a transaction:
--
      pragma foreign_keys = on;
      insert into child values (2);
commit;

pragma foreign_keys=on;
-- 
-- Not possible, foreign keys are now enforced.
-- The following statement, if uncommented, causes
-- error message
--   Error: near line 27: FOREIGN KEY constraint failed
--
--   insert into child values (3);
Github repository about-sqlite, path: /sql/pragma/foreign_keys.sql
Explicitly turning off the validation of foreign keys might be useful when importing a .dump'ed database.

See also

The foreign_key_check pragma.

Index