How to enable Foreign Key constraints in SQLite when writing tests in Laravel

Recently found one of my test failing due to my inmemory SQLite  database not enforcing foreign key constrains.

Googled around and found a solution for it, reposting that solution here so i can easily find it in the future, and that other people can more easily find a copy-pastable solution.


Put the following code in your AppServiceProvider file within the boot() method:



Leave a Reply

Your email address will not be published. Required fields are marked *