Reverse migration / drop foreign key for custom index name laravel migration

  laravel, laravel-migrations, mysql

So I have this migration

public function up()
        Schema::table('xxx', function (Blueprint $table) {
            $table->foreign('aaa','bbb') // handle identifier name too long

I want create the down() function / reverse the migration for remove this foreign key.

What I have tried here:

public function down()
        Schema::table('xxx', function (Blueprint $table) {
            // implement one line of all 4 possibilities
            $table->dropForeign(['aaa'], 'bbb');
            $table->dropForeign(['bbb'], 'aaa');

All giving the same error when I run rollback this migration file,

SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'zzz'; check that column/key exists

The database condition is still clean, no data (row) inserted. If I do it without the custom name assigned to second argument in foreign and short name case (no warning abount identifier name too long), the reverse migration runs smoothly.

Source: Laravel

Leave a Reply