laravel: Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation...

4424012-901b210beb0ec6a2.png
使用mysql版本为8.0

使用php artisan migrate命令提示Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

4424012-161c08be0a2464c4.png
image.png

解决

1 修改\app\Providers下面AppServiceProvider.php

public function boot()
    {
        Schema::defaultStringLength(191);
    }

如果报错,头部添加use Illuminate\Support\Facades\Schema;

4424012-81aac71b421e8d5b.png
image.png

2 修改 /config/database.php

'engine' => null'改成 
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

3 清空缓存

php artisan cache:clear
php artisan config:clear

4 在执行php artisan migrate

4424012-49c90860266004a8.png
搞定

转载于:https://www.jianshu.com/p/651ccb3f3109

猜你喜欢

转载自blog.csdn.net/weixin_34124939/article/details/91330691