Shree Krishna Lamichhane

Shree Krishna Lamichhane

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

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

Subscribe to my newsletter and never miss my upcoming articles

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