Shree krishna lamichhane
Shree Krishna Lamichhane

Follow

Shree Krishna Lamichhane

Follow
Solution to 1071:Specified key was too long problem in Laravel.

Solution to 1071:Specified key was too long problem in Laravel.

Shree krishna lamichhane's photo
Shree krishna lamichhane
·Jul 21, 2021·

1 min read

Hi there, If you encountered this error message on laravel

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;

Then here's a quick fix, All you have to do is to add the following code in the

app\Providers\AppServiceProvider.php.

use Illuminate\Support\Facades\Schema;

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

Now run a fresh migration with

php artisan migrate:fresh

This will solve the problem.

Happy Coding.

 
Share this