How to Drop foreign keys in Laravel migration



If you would try to run $table->dropForeign([column_name]);
to drop key it will drops the index and not the column itself. 🤔

_________________________________________________

So solution of this problem is:

SolutionFunction drop the index in first schema and then drop the actual column in a second schema.

We will use down function for this:

public function down() {
    // drop the keys
Schema::table('role_user', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['role_id']);
}); // drop the actual columns
Schema::table('role_user', function (Blueprint $table) {
$table->dropColumn('user_id');
$table->dropColumn('role_id'); });
}

Now you should run php artisan migrate to run the up function.

After this run php artisan migrate:rollback to run the down command.

Thank you