When you run the migration command in Laravel you will get the following error
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
oo long; max key length is 767 bytes (SQL: alter tableusers
add unique(
users_email_unique
Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Reason for the error
Laravel 5.4 has done changes for the default charset of the database. It is now utf8mb4
How to fix this error
1 Upgrate your MySql Database to v5.7.7 and higher
2 You can edit the AppServiceProvider.php
file which is located app>Providers location
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } /** * Register any application services. * * @return void */ public function register() { // } } |