# Laravel: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

**Code:** `Specified key was too long; max key length is 1000 bytes` · **Category:** Laravel · **Seen on:** Laravel, PHP, MySQL

An indexed string column exceeds the index size allowed by an older MySQL/MariaDB with utf8mb4.

## 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

1. `Schema::defaultStringLength(191);` in `AppServiceProvider::boot`
2. Upgrade MySQL to 5.7.7+ / MariaDB 10.2.2+
3. Or use 191-length columns for indexed fields

## Detailed fix by platform

### Laravel

1. in `app/Providers/AppServiceProvider.php`: `use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }`

## How to diagnose

1. **DB** — Version?
2. **Column** — Indexed varchar length?
3. **Charset** — utf8mb4?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/migration-specified-key-too-long)
