laravel 1071指定的密钥太长;最大密钥长度为1000个字节

问题描述 投票:0回答:1
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `translations` add unique `translations_table_name_co
lumn_name_foreign_key_locale_unique`(`table_name`, `column_name`, `foreign_key`, `locale`))

我添加此

use Illuminate\Support\Facades\Schema;
Schema::defaultStringLength(191);

但是什么都没有改变,仍然出现此错误

laravel
1个回答
0
投票

应该是:

app/providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

一个临时解决方案将转到您的[[config/database.php并将字符集和排序规则从utf8mb4更改为utf8

'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',
这是因为utf8mb4每个字符使用4个字节,并且该列的255字符长度大于限制767 bytes255 x 4bytes = 1020b

要解决此问题,电子邮件列的长度最多应为191191 x 4 bytes = 764b

© www.soinside.com 2019 - 2024. All rights reserved.