[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Option 1: Update default String Length
The first option is to change the default string length and you can define this in the AppServiceProvider. This is the most common method that should do the fix but if you still having error then do check the option 2 below.
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } }
Opton 2: Update Config/Database.php File
The next option is to update the "config/database.php" file for the "mysql array" configuration. Do update the value below for the "mysql" config and re-run the migration.
'mysql' => [ 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', ]
php artisan migrate // or php artisan migrate:fresh
php artisan config:clear
Leave a reply