Fixing syntax error or access violation 1071 specified key was too long max key length is 767 bytes

Share:

Fixing syntax error or access violation 1071 specified key was too long max key length is 767 bytes

[Illuminate\Database\QueryException]
 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))

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

Solution:-Remove all migrated tables first from database.

Then,In App/Providers/ folder open "AppServiceProvider.php" and add below codes.

Step 1. On add "use Illuminate\Support\Facades\Schema;" under namespace App\Providers;.
Step 2. In boot method add Schema::defaultStringLength(191);


No comments