Igor Simic
4 years ago

Laravel - Syntax error or access violation: 1071 Specified key was too long


If you are seeing this error when running artisan migrate command, do not worry there is an easy fix for this. Laravel uses the utf8mb4 character set by default, and users who are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release could experience this issue.

According to Laravel documentation, the fix is to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:
use Illuminate\Support\Facades\Schema;/**
 * Bootstrap any application services.
 *
 * @return void
 */public function boot(){
    Schema::defaultStringLength(191);
}
And now you should be able to run your migrations.

You are welcome.