Access violation error in Laravel 5.4 migration

When we setup a fresh laravel 5.4 and tried to run default user tables migration

php artisan migrate

then we got a below error

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_

After searching for this error in google, we came to know that it is due to mysql database engine updation. There are few solutions recommended in few places. We tried them but couldn’t get worked. Later we tried the below solution, it got worked

Step 1: Include Facades/Schema in AppServiceProvider.php file

use Illuminate\Support\Facades\Schema;

Step 2: Edit your AppServiceProvider.php file and inside the boot method set a default string length-

public function boot()

Step 3: Drop users, password_resets, migrations tables in the database if already created.

Step 4: Finally, run the php artisan migrate command. Done!.

We hope it might help someone who got this issue.




Related posts