I have installed Laravel 8 on PHP 7.4. Problem occur when try to run ‘php artisan migrate’ on this code base. Showing the error below:
Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table permissions
add unique permissions_name_guard_name_unique
(name
, guard_ name
))
To solve this issue first need to open the AppServiceProvider.php file in Providers folder and go to find the boot function and write this line Schema::defaultStringLength(191) in the boot function, also do not forget import the name space use Illuminate\Support\Facades\Schema like below :
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
Till not the problem gone. So the next step is here: open the database.php file in config folder and find this
‘engine’ => null,
and replace with this below
‘engine’ => ‘InnoDB ROW_FORMAT=DYNAMIC’,
Now it’s look like below:
'mysql' => [
...,
...,
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
]
After the all run this in terminal : php artisan config:cache
Some time also work this changes in database.php file in config folder:
Edit the line below
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
to
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
Now it’s fine to run my migration.
You can understand about this error more from the references below.
References: