美文网首页
laravel 5.4 数据库错误问题

laravel 5.4 数据库错误问题

作者: Red_zhang | 来源:发表于2017-05-18 23:21 被阅读0次

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 数据库错误问题

      本文链接:https://www.haomeiwen.com/subject/auyexxtx.html