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);
但是什么都没有改变,仍然出现此错误
应该是:
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 bytes
。255 x 4bytes = 1020b
。要解决此问题,电子邮件列的长度最多应为
191
。191 x 4 bytes = 764b