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

When trying to migrate the Auth database tables on a fresh Laravel 5.4 install I got the following error.

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

Aftera bit of Google’ing I found a solution that workded for me.

Add the following line in the users migration file.

 Schema::defaultStringLength(191);

So the create_users_table should look like this.

public function up()
    {
        Schema::defaultStringLength(191);
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

Original solution was found here.

Leave a Reply

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