If you use Laravel in combination with an older version of MySQL, you may see an error like “1071 Specified key was too long; max key length is 1000” when running migrations.
To fix this error, you have to modify app/Providers/AppServiceProvider.php:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; // add this line
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191); // add this line
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
Add both lines, marked with the comment “add this line”.
After that, modify your config/database.php and change the mysql setting
'engine' => null,
to
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
Last step is to clear config and cache. Run this commands from your terminal:
php artisan cache:clear
php artisan config:clear
Now, you should be able to run your migrations:
php artisan migrate