Search code examples
laravellaravel-artisanmigrate

In Facade.php line 237: Call to undefined method Illuminate\Database\Schema\MySqlBuilder::defaultStringLenght()


I am trying migrate a MySQL table in Laravel5.8 thru command

$ php artisan migrate

I am getting this error

In Facade.php line 237: 
    Call to undefined method 
    Illuminate\Database\Schema\MySqlBuilder::defaultStringLenght()

I already set in AppServiceProvider.php file use Illuminate\Support\Facades\Schema;
defaultStringLenght(191); // boot() method

Schema::create('posts', function (Blueprint $table) {
      $table->increments('id');  
      $table->string('title'); 
      $table->mediumText('body');
      $table->timestamps(); 
    });

Solution

  • In the app\Providers\AppServiceProvider.php you need to use

    use Illuminate\Support\Facades\Schema; 
    

    and then in the boot function you need to write Schema::defaultStringLength(191); and your boot function will look like this

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