在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
我已经解决了这个问题,并编辑我的config->database.php文件喜欢我的数据库('charset'=>'utf8')和('collation'=>'utf8_general_ci'),所以我的问题解决了如下代码:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
模式:defaultStringLength (191);将默认定义所有字符串191的长度,这可能会破坏您的数据库。你不能走这条路。
只需在数据库迁移类中定义任何特定列的长度。例如,我在CreateUsersTable类中定义了“name”,“username”和“email”,如下所示:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 191);
$table->string('username', 30)->unique();
$table->string('email', 191)->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}