我已经创建了一个表堆栈链接,如下所示

Schema::create('stack_links', function (Blueprint $table) {
            $table->increments('id');
            $table->string('site_key');
            $table->string('url');
            $table->string('path_run')->nullable();
            $table->integer('state');
            $table->integer('parent')->nullable();
            $table->text('data');
            $table->timestamps();

            $table->unique(['site_key', 'url']);

            $table->index(['site_key']);
            $table->index(['state']);
            $table->index(['parent']);
            $table->index(['url']);
        });

现在我想把url列改为文本类型。所以我试过了
 $table->text('url')->change();

但是它会返回这个错误
1170 BLOB/TEXT column 'url' used in key specification without a key length

在搜索之后,我发现错误是因为url被索引(MySQL error: key specification without a key length)。所以我删除了索引,但仍然是同样的错误。我明白:https://laravel.com/docs/5.5/migrations#dropping-indexes
Schema::table('stack_links', function (Blueprint $table) {
            $table->dropUnique(['url']);
            $table->dropIndex(['url']);

            $table->text('url')->change();
            $table->string('md5_url');

            $table->unique('md5_url');
            $table->index('md5_url');
        });

有人能告诉我哪里错了吗。
更新:问题是dropIndex的参数。当我用索引的名称替换它时。它起作用了

最佳答案

尝试DB Statement-

 public function up()
{
    DB::statement('ALTER TABLE stack_links DROP INDEX stack_links_url_index');
    DB::statement('ALTER TABLE stack_links MODIFY COLUMN url TEXT');
}
public function down()
{
    DB::statement('ALTER TABLE stack_links CREATE INDEX stack_links_url_index');
    DB::statement('ALTER TABLE stack_links MODIFY COLUMN url STRING');
}

10-07 22:02