[报错:字符太长]SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long;

作者: JONE 分类: PHPer 发布时间: 2019-12-14 20:08

查阅了下资料说是mysql版本低

解决办法:
可以在 AppServiceProvider.php 文件(此文件在app/Providers/下)里的 boot 方法里设置一个默认值:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

参考地址:https://laravel.com/docs/master/migrations#creating-indexes