【发布时间】:2018-06-18 02:24:50
【问题描述】:
我已经创建了一个表 stack_links 如下
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的参数上。当我用索引的名称替换它时。它的工作原理
【问题讨论】:
-
stackoverflow.com/questions/1827063/… 关注这个我想这会对你有所帮助。
-
@KuldeepMishra 我删除了索引,但它仍然记录相同的错误
-
laravel.com/docs/5.5/migrations你检查过这个链接了吗??
-
伙计,如果您开始处理大量记录,那么在
url上使用unique对您来说将非常昂贵。现在,关于您的问题,当您希望它成为index时,您绝对必须在text列上使用length。所以...例如$table->text('url', 1024)->change()。 -
@KuldeepMishra 把我应该纠正的地方写出来,请不要写链接,因为我已经读过了,但可能我还不够了解