Syntax error or access violation: 1071 Specified key was too long

When running database migration in a new larvel project, i get following error

boby@hon-pc-01:~/www/proxy (master)$ php artisan migrate

In Connection.php line 664:

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

In Connection.php line 458:

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

boby@hon-pc-01:~/www/proxy (master)$

This is due to recent change in Lavral, that changed default charset to utf8mb4.

To fix this error, open file

vi app/Providers/AppServiceProvider.php

Find

use Illuminate\Support\ServiceProvider;

Add below

use Illuminate\Support\Facades\Schema;

Find

    public function boot()
    {
        //
    }

Replace with

    public function boot()
    {
        Schema::defaultStringlength(191);
    }
Need help with Linux Server or WordPress? We can help!

Leave a Reply

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