我有以下错误。有人正在理解为什么?Php artisan migrate failed Laravel
PHP工匠迁移
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key
was too long; max key length is 767 bytes (SQL: alter table `users`
add unique `users_email_unique`(`email`))
create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',255);
$table->string('email',255)->unique();
$table->string('password',255);
$table->rememberToken();
$table->timestamps();
});
这是因为性格与'email'现场使用设定的。 1个字符不会是1个字节,它可能是* 4个字节。当您尝试使该字段唯一时,它会失败,因为该列索引太长。解决这个问题的方法是创建另一个包含'email'的** hash **的列。你可以创建该列'email_hash binary(20)',然后保存该邮件的原始'sha1'哈希值并使其唯一。这使得你的索引总是长度为20个字节,并且适用于你的用例。 –