Skip to main content
100%

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

✓ Published0🌍 Public
MMistyBlunch
Last edited Aug 4, 2018
Created on Aug 4, 2018

This example shows a Laravel error message, SQLSTATE[42000], that occurs when creating a unique index on an email column, where the key exceeds the maximum 1000-byte limit. The fix involves setting `Schema::defaultStringLength(191)` before defining the `users` table schema with the Blueprint API, which shortens the default string length so the unique constraint fits within the limit. The code uses Laravel's Schema builder and Blueprint class to define the table structure, including the `string()` and `unique()` methods for the email field.

AI-generated description

Similar vizzes