Dusk Failing on Teardown - `foreign key constraint fails`

1 minute read

April 30, 2018

When running a dusk test, I was getting the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails

And for the longest time I couldn't figure it out. I reinstalled dusk, tried to run the default test, and more.

I ended up digging into the DatabaseMigrations trait and realized that on teardown, the trait tries to rollback migrations instead of dropping them.

To fix the issue I added DB statements to turn off the foreign key checks after looking at this StackOverflow post.

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    DB::statement('SET FOREIGN_KEY_CHECKS = 0');
    Schema::dropIfExists('products');
    DB::statement('SET FOREIGN_KEY_CHECKS = 1');
}

Laravel dusk testing

Looking for more?

WIP: Laracon 2018

Laracon was this past week and it was amazing! Last night I tweeted this out:

I don't know where to begin, or how to fit everything I'm feeling into a tweet, but...

Jul 27, 2018

2 minute read

My Work Spotify Playlists

Here's a list of playlists I rotate through when I need get down to business.

  • Deep Work created by Chris Gmyr
  • Deep House Relax created by Spotify
  • mint...

May 14, 2018

1 minute read