When migrating my DB, this error appears. Below is my code followed by the error that I am getting when trying to run the migration.
Code
One way to get around foreign key errors is to disable checking: "SET FOREIGN_KEY_CHECKS". This is a palliative solution, but the correct thing is really to adjust the tables and their relationships.
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Schema::table('example', function (Blueprint $table) {
$table->integer('fk_example')->unsigned()->index();
$table->foreign('fk_example')->references('id')->on('examples');
});
DB::statement('SET FOREIGN_KEY_CHECKS=1;');