When using SQLite for in-memory tests, I discovered that foreign keys are not used by default. Not so bad until you test cascading deletes and cry rivers of ones and zeros… Do I really have to make a test database?! I thought this was America! WHHHYYYYYYYYYYY?!?!?!?!?!?!
With a bunch of Googling I found that it is possible to enable foreign keys in SQLite. They are just turned off by default to cause sadness and confusion. To enable, you can use the code below.
But where to put it? I don’t want that thing chilling in my app. I only need it for testing at the moment. I extend the TestCase class for all my tests so I dropped it in the createApplication method like so:
I hope that helps someone. Here’s one of the articles that I pulled code from.