Laravel Specified key was too long error?

i have problem using laravel migration command

 Illuminate\Database\QueryException SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
 
PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes") 

Default Asked on June 18, 2020 in Programming.
Add Comment
1 Answer(s)

As indicated by the official documentation, you can solve this without any problem.

Include the accompanying two lines of code to AppServiceProvider.php

(/app/Providers/AppServiceProvider.php)

 

use Illuminate\Database\Schema\Builder; // Import Builder where defaultStringLength method is defined
 
function boot()
{
    Builder::defaultStringLength(191); // Update defaultStringLength
}
 
Default Answered on June 21, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.