Fixing laravel 5.4 Specified key was too long error

If you are using Laravel 5.4, you might have encountered an error saying syntax error or access violation: 1071 Specified Key was too long; max key length is 767 bytes

In order to resolver this error and make Laravel work again , we need to use a little tweak in AppServiceProvider.php

Open AppServiceProvider.php which is in the path \app\Providers\AppServiceProvider.php

There add the line

use Illuminate\Support\Facades\Schema;

under use Illuminate\Support\ServiceProvider;

Inside the boot method add the line

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

This will set the error and makes Laravel work again

You can find more about this in the Migrations Guide of Laravel

Laravel,specified key error