Laravel - How to remove foreign key constraint using migration?

By Hardik Savani February 18, 2023 Category : Laravel

Sometimes it can be agreeable to remove a database column that hosts a foreign key relationship, and we add wrong column with foreign key constraint on table, At that time we must remove that column from table. here, we will remove foreign key constraint using migration in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10.

But we can't remove directly using dropColumn() because we did apply foreign key constraint so we should drop foreign key constraint of that column using dropForeign() and then we can delete column using dropColumn(). You can see as bellw migration, first i added migration with wrong column then other migration for remove that column.

Wrong Column Migration:

Schema::create('admins', function (Blueprint $table) {





$table->string('password', 60);





Drop Column Migration:

Schema::table('admins', function (Blueprint $table) {




We are Recommending you