Laravel 5.4-在外键上删除唯一约束时出错

Laravel 5.4-在外键上删除唯一约束时出错,laravel,foreign-keys,unique-constraint,laravel-migrations,Laravel,Foreign Keys,Unique Constraint,Laravel Migrations,我试图删除一个唯一约束,但一直遇到外键约束问题: 以下是原始迁移: Schema::table('table', function (Blueprint $table) { $table->bigInteger('other_table_id')->unsigned()->unique()->nullable(); $table->foreign('other_table_id')->references('id')->on('other

我试图删除一个唯一约束,但一直遇到外键约束问题:

以下是原始迁移:

Schema::table('table', function (Blueprint $table) {
    $table->bigInteger('other_table_id')->unsigned()->unique()->nullable();
    $table->foreign('other_table_id')->references('id')->on('other_table')->onDelete('set null');
});
Schema::disableForeignKeyConstraints(); // Disable constraint

Schema::table('table', function (Blueprint $table) {
    $table->dropUnique(['other_table_id']);
});

Schema::enableForeignKeyConstraints(); // Reenable constraint
快进到现在,我试图在不影响外键的情况下从表的列中删除唯一约束

这是我得到的错误

SQLSTATE[HY000]: General error: 1553 Cannot drop index 'table_other_table_id_unique': needed in a foreign key constraint
我也试过使用

Schema::table('table', function (Blueprint $table) {
    $table->dropUnique(['other_table_id']);
});
但这也不起作用

我甚至尝试在迁移时禁用外键约束:

Schema::table('table', function (Blueprint $table) {
    $table->bigInteger('other_table_id')->unsigned()->unique()->nullable();
    $table->foreign('other_table_id')->references('id')->on('other_table')->onDelete('set null');
});
Schema::disableForeignKeyConstraints(); // Disable constraint

Schema::table('table', function (Blueprint $table) {
    $table->dropUnique(['other_table_id']);
});

Schema::enableForeignKeyConstraints(); // Reenable constraint
似乎什么都不管用。我做错了什么

乔尔·辛兹的评论足以回答我的问题。我在回答我自己的问题,因为我可以用特定于Laravel的代码提供答案

问题源于使用唯一密钥作为其密钥的外键。因此,必须在删除唯一密钥之前删除外键,然后再次设置外键

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('table', function (Blueprint $table) {
        $table->dropForeign(['other_table_id']);
        $table->dropUnique(['other_table_id']);

        $table->foreign('other_table_id')->references('id')->on('other_table')->onDelete('set null');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('table', function (Blueprint $table) {
        $table->unique('other_table_id');
    });
}

@JoelHinz谢谢你的链接。它给了我足够的信息来回答我自己的问题。我已经用下面的解决方案回答了这个问题。不过,我会将您的链接标记为答案。