Fix Laravel: Specified key was too long

Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for emojis. For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:

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

Edit your AppServiceProvider.php file and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }


Explore our projects