1071 Specified key was too long – Laravel 5.4

September 21, 2019

by Yunus Shaikh

HOW TO FIX – 1071 SPECIFIED KEY WAS TOO LONG ERROR

[IlluminateDatabaseQueryException] 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


To fix this issue

Go to app/Providers/AppServiceProvider.php file and add following code into boot method


public function boot()
{
  Schema::defaultStringLength(191);
}


    use Illuminate\Support\Facades\Schema;