【发布时间】:2019-11-11 16:06:04
【问题描述】:
我有这样的迁移:
Schema::table('table', function (Blueprint $table) {
$table->string('description', 500)->index()->change();
});
但我收到此错误:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `...` add index `tags_description_index`(`description`))
我尝试过的:
(1) 将->index() 更改为index("t_index")。同样的错误。
(2) 在AppServiceProvider:
public function boot()
{
Schema::defaultStringLength(512);
}
同样的错误。
不知道该怎么办。我在本地环境中没有收到错误,只是现在我正在尝试部署。
【问题讨论】:
-
尝试在您的服务器上安装更新的 mysql 版本(MySQL
-
或者,仅索引文本的前 x 个字符。你需要使用类似
DB::statement('ALTER TABLE table ADD INDEX description (description(10));')