在Laravel 5.4上使用php artisan make:auth迁移错误
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e users add unique users_email_unique(email))
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
对于这个错误,我找到了两个解决方案
选项1:
打开database/migrations文件夹下的user和password_reset表
只需要改变邮件的长度:
$table->string('email',191)->unique();
选项2:
打开app/Providers/AppServiceProvider.php文件,在boot()方法中设置一个默认字符串长度:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
1-进入/config/database.php,找到这些行
'mysql' => [
...,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
...,
'engine' => null,
]
并更改为:
'mysql' => [
...,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
...,
'engine' => 'InnoDB',
]
2-运行php artisan config:cache重新配置laravel
3-删除数据库中现有的表,然后再次运行php artisan migrate