Support the ongoing development of Laravel.io →
posted 10 years ago
Database

I have the following migration:

<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateTeamsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('teams', function($table){ $table->increments('id'); $table->string('name'); $table->text('description'); $table->timestamps(); $table->integer('league_id')->unsigned(); $table->foreign('league_id')->references('id')->on('leagues'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('teams', function($table){ $table->dropForeign('teams_league_id_foreign'); }); Schema::drop('teams'); } } Now if I run the rollback it fails with: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table `leagues`) this is the order of the migrations: Migrated: 2014_05_16_161718_create_league_table Migrated: 2014_05_20_190133_create_teams_table however running "alter table teams drop foreign key teams_league_id_foreign" it works and enables deletion. Is laravel ignoring this migration? What's going on?
Last updated 3 years ago.
0

Did you try to remove the manual foreign key removal and just leave the method with Schema::drop() ?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

juanfgs juanfgs Joined 3 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.