ERROR #1071 – Specified key was too long; max key length is 767 bytes

Laravel 7.X | 8X | 9X: Simple Solution.

Option-1:

php artisan db:wipe 

Update these values(Below) of mysql array in /config/database.php

'charset' => 'utf8', 'collation' => 'utf8_general_ci',

And then

php artisan migrate

It’s Done! Migration Tables will be created successfully.


Option-2:

Use php artisan db:wipe or delete/drop all the tables of your database manually.

Update your AppServiceProvider.php [ Located in app/Providers/AppServiceProvider.php ]

use Illuminate\Support\Facades\Schema;
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191); 
}

And then

php artisan migrate

It’s Done!

Pitfall: I would like to mention of @shock_gone_wild ‘s comment

Be careful about this solution (Option-2). If you index email fields for example, stored emails can only have a max length of 191 chars. This is less than the official RFC states.


Optionally I Tried out these possible ways (like below) but doesn’t work.

php artisan config:cache php artisan migrate:fresh

php artisan migrate:reset