Laravel: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
An indexed string column exceeds the index size allowed by an older MySQL/MariaDB with utf8mb4.
Specified key was too long; max key length is 767 bytesSQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too longmax key length is 1000 bytes LaravelSyntax error or access violation: 1071 Specified key was too long Meaning
Laravel defaults to utf8mb4 (4 bytes per char), so varchar(255) indexed = 1020 bytes, over the 767/1000-byte limit on old MySQL (< 5.7.7) or MariaDB (< 10.2.2). Upgrade the DB, enable innodb_large_prefix with DYNAMIC rows, or set Schema::defaultStringLength(191) in AppServiceProvider::boot().
Common causes
- Old MySQL/MariaDB version
- ROW_FORMAT not DYNAMIC
- Unique index on a long varchar
- utf8mb4 charset on legacy server
- Shared hosting DB defaults
⚡ Quick fix
Schema::defaultStringLength(191);inAppServiceProvider::boot- Upgrade MySQL to 5.7.7+ / MariaDB 10.2.2+
- Or use 191-length columns for indexed fields
Detailed fix by platform
Laravel
- in
app/Providers/AppServiceProvider.php:use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
How to diagnose
- DB — Version?
- Column — Indexed varchar length?
- Charset — utf8mb4?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026