Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activate foreign keys after importing a SQlite3 dump

When I import a DUMP into an SQlite3 database I manually have to activate the foreign_keys again afterwards.

PRAGMA foreign_keys = ON;

When creating a dump the dump looks like this:

PRAGMA foreign_keys = OFF;
BEGIN TRANSACTION;
[...]
COMMIT;

When I add the activation command manually it is ignored:

PRAGMA foreign_keys = OFF;
BEGIN TRANSACTION;
[...]
COMMIT;
PRAGMA foreign_keys = ON;

Is there a way to reactivate the foreign_keys automatically when a Dump is imported?

like image 455
Frille2012 Avatar asked Dec 12 '25 10:12

Frille2012


1 Answers

The PRAGMA foreign_keys = ON; does activate foreign keys. However, this setting is not stored in the database. You have to execute this pragma for every new connection to the database.

like image 153
CL. Avatar answered Dec 16 '25 05:12

CL.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!