How to solve Specified key was too long error in laravel migration

As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema; 

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

}

Solution2: Specify a smaller length for particular column

Example:

$table->string('email', 191);

Leave a Comment

Your email address will not be published. Required fields are marked *