Skip to main content

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




When you initally migrate to the database you might get this error:



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

So, to solve this error open your AppServiceProvider.php  which is inside App\Provider\AppServiceProvider.

import this at the top:

use Illuminate\Support\Facades\Schema;


and write Schema::defaultStringLength(191); inside the boot function. Like this:


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

Now, Delete User and migration tables from the database. Otherwise you will see that error again.


Now, run the migration again.

Thanks!

Comments

Popular posts from this blog