laravel 5.4 数据库错误问题

zhang@love-cc MINGW64 /d/Hello

$ php artisan migrate

Migration table created successfully.

[Illuminate\Database\QueryException]

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `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 1000 bytes

刚安装好的laravel 5.4版本,运行php artisan migrate时,出现了错误

然后在

https://laravel.com/docs/master/migrations#creating-indexes

这里找到了出错的解决方案:

Index Lengths & MySQL / MariaDB

Laravel uses theutf8mb4character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling theSchema::defaultStringLengthmethod within yourAppServiceProvider:

useIlluminate\Support\Facades\Schema;

/**

* Bootstrap any application services.

*

* @return void

*/

publicfunctionboot(){

Schema::defaultStringLength(191);

}

Alternatively, you may enable theinnodb_large_prefixoption for your database. Refer to your database's documentation for instructions on how to properly enable this option.

你可能感兴趣的:(laravel 5.4 数据库错误问题)