Fix the "Specified key was too long error"

Submitted by AdeLDev - 6 years ago

If You're raning Laravel 5.4, You May Get An Error While You'are Migrate Or Dealing with the db . The Error is look like : [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

use Illuminate\Support\Facades\Schema;

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