laravel5.5报错:1071 Specified key was too long; max key length is 767 bytes

xiaoxiao2021-02-28  44

原因:laravel改变了默认的数据库字符集,现在使用utf8mb4,如果你使用的MySQL数据库高于5.7就不会报错,如果低于该版本就会报错

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

解决方案:在AppServiceProvider添加代码: Schema::defaultStringLength(191); 完整的代码:

use Illuminate\Support\Facades\Schema;//一定要记得引入Schema /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); }
转载请注明原文地址: https://www.6miu.com/read-2350133.html

最新回复(0)