Skip to content

Instantly share code, notes, and snippets.

@EduardoSP6
Last active January 8, 2025 19:06
Show Gist options
  • Save EduardoSP6/f67fbee016081d636dfdf15a4e3d7c89 to your computer and use it in GitHub Desktop.
Save EduardoSP6/f67fbee016081d636dfdf15a4e3d7c89 to your computer and use it in GitHub Desktop.
How to drop index Mysql 8 using Laravel [Error: 1553]

How to drop index Mysql 8 using Laravel [Error: 1553]

[General error: 1553 Cannot drop index needed in a foreign key constraint]

Este erro ocorre quando já existe uma chave estrangeira em um campo e tentamos criar um índice para o campo. Em alguns casos este erro pode ocorrer ao efetuar rollback na migration.

Método para solução do erro:

public function down() 
{
  Schema::disableForeignKeyConstraints();
  DB::query("DROP INDEX expenses_type_expense_id_index ON expenses");
  Schema::enableForeignKeyConstraints();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment