xxxxxxxxxx
public function up()
{
Schema::table('your_table_name', function (Blueprint $table) {
// Drop foreign key constraint
$table->dropForeign(['your_foreign_key']);
});
}
xxxxxxxxxx
Schema::table('posts', function (Blueprint $table) {
$table->dropForeign(['category_id']);
});
xxxxxxxxxx
//...
class ClearOldOauthRelations extends Migration
{
public function up()
{
Schema::disableForeignKeyConstraints();
// drop foreign keys
Schema::table('oauth_access_tokens', function (BluePrint $table) {
$table->dropForeign('oauth_access_tokens_session_id_foreign');
});
//...
Schema::enableForeignKeyConstraints();
}
//...
}
xxxxxxxxxx
public function down()
{
if (Schema::hasTable('leads')) {
Schema::table('leads', function (Blueprint $table) {
$table->dropForeign('leads_dealer_id_foreign'); //this is the line
$table->dropIndex('leads_dealer_id_index');
$table->dropColumn('dealer_id');
});
Schema::dropIfExists('leads');
}
}
xxxxxxxxxx
Schema::table('table_name', function (Blueprint $table) {
$table->dropForeign(['foreign_key']);
$table->dropColumn('column_key');
});
PS: usually foreign_key = column_key
ex:
Schema::table('despatch_discrepancies', function (Blueprint $table) {
$table->dropForeign(['pick_detail_id']);
$table->dropColumn('pick_detail_id');
});
xxxxxxxxxx
public function down()
{
Schema::table('tarefas', function (Blueprint $table) {
$table->dropForeign('tarefas_user_id_foreign');
$table->dropColumn('user_id');
});
}
xxxxxxxxxx
// Primary table name, from Schema::table(<table>)
// Primary column, from $table->foreign(<column>)
$table->dropForeign('<table>_<column>_foreign');
xxxxxxxxxx
// Searched, laravel drop foreign column
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['votes', 'avatar', 'location']);
});