You configure your database credentials, run php artisan migrate to build your tables, and the migration crashes halfway through the users or jobs table with this terminal error:
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (Connection: mysql, SQL: alter table `users` add unique `users_email_unique`(`email`))
Enter fullscreen mode
Exit fullscreen mode
Depending on your MySQL or MariaDB version, the error message will state a max key length of 1000 bytes , 767 bytes , or 3072 bytes .
The Math Behind the Crash
By default, Laravel uses the utf8mb4 character set so your database can store full Unicode characters and emojis. Unlike older utf8 (which uses 3 bytes per character), utf8mb4 reserves up to 4 bytes per character .
When a migration creates a standard string column ( $table->string('email')->unique() ), Laravel sets it to VARCHAR(255) .β¦