Laravel drop foreign Key in Migration Laravel drop foreign Key in Migration php php

Laravel drop foreign Key in Migration


You can use this answer. https://stackoverflow.com/a/30177480/8513937

Pass to dropForeign the column name as array. Internally, Laravel drops the associated foreign key.

$table->dropForeign(['client_id']);


You just need to disable foreign key checks before you drop the table then enable them again after like this:

DB::statement('SET FOREIGN_KEY_CHECKS=0;');Schema::dropIfExists('devices');DB::statement('SET FOREIGN_KEY_CHECKS=1;');


Try this ways...

  public function down() {    Schema::dropIfExists('devices'); }//Or this  public function down(){    Schema::table('devices', function (Blueprint $table) {        $table->dropForeign(['client_id']);        $table->dropColumn('client_id');        $table->drop('devices');    });  }