1071 Specified key was too long; max key length is 767 bytes (Laravel)

Lim Sing
1 min readJul 14, 2020

--

This error happen on new applications and using MariaDB or MySQL which lower than v5.7.7 when you try to run php artisan migrate.

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`))

Solution:

Go to your AppServiceProvider.php file, and add this following code in boot function:

use Illuminate\Support\Facades\Schema;

public function boot() {

Schema::defaultStringLength(191);

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Lim Sing
Lim Sing

No responses yet

Write a response