Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

When you run the migration command in Laravel you will get the following error

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
oo long; max key length is 767 bytes (SQL: alter table users add unique
users_email_unique
(email))

Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Reason for the error
Laravel 5.4 has done changes for the default charset of the database. It is now utf8mb4


How to fix this error

1 Upgrate your MySql Database to v5.7.7 and higher

2 You can edit the AppServiceProvider.php file which is located app>Providers location

Leave a Reply

Your email address will not be published. Required fields are marked *