In SQLite, foreign key constraints are disabled by default.
What\'s the best way to configure Laravel 5.1\'s SQLite database connection to enable foreign key constra
Since I only want to use this in my tests, but in all tests, I ended up with a simple implementation in the Tests\TestCase class like this:
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp()
{
parent::setUp();
$this->enableForeignKeys();
}
/**
* Enables foreign keys.
*
* @return void
*/
public function enableForeignKeys()
{
$db = app()->make('db');
$db->getSchemaBuilder()->enableForeignKeyConstraints();
}
}
This works like a charm :-)