Tag

Migration

Browsing

One day I install Laravel 5.6 When I am going to create a migration for the Laravel application. Then I run Laravel migration command I got an error like 1071 specified key was too long max key length is 767 bytes. I find the solution why I got Laravel 1071 specified key was too long error when I run the migration.

Since Laravel 5.4 change the default database character set to “utf8mb4” for includes support for storing emojis. This only affects If you running MariaDB or older versions of MySQL. You may hit this error when you are running migration command.

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

PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes”)

As per Laravel 5.4.* documentation, You need to set default string length on Boot method for the resolving this issue.

Laravel 5.6 – 1071 specified key was too long

First of all, Open the App Service Provider at “app/Providers/AppServiceProvider.php” then follow below steps.

After, applying that solution everything is working fine. Still, if you face any issue write the command below.