Laravel 5.8 specified key was too long error - Solved

March 26, 2019 | Category : Laravel 5.8 Laravel 5 Laravel PHP

Just tomorrow i was installing laravel 5.8 and run migration at that time i got specified key was too long error in migration. you can see it was same error bellow message:

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

Than i checked with user table migration but over there everything is fine in code. but when i saw unique() on my email and i remove it that it was works fine. So i found it was issue from my mysql version or something. If you have also this same error on migration than you can solve by adding defaultStringLength() of Schema in AppServiceProvider.

Just see bellow code on service provider file:

App\Providers\AppServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider

{

/**

* Register any application services.

*

* @return void

*/

public function register()

{

//

}

/**

* Bootstrap any application services.

*

* @return void

*/

public function boot()

{

Schema::defaultStringLength(191);

}

}

I hope you found your best solution....