Showing posts with label Schema::defaultStringLength. Show all posts
Showing posts with label Schema::defaultStringLength. Show all posts

Tuesday, 8 August 2023

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

Error:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes. (Connection: mysql, SQL: alter table `permissions` add unique `permissions_name_guard_name_unique`(`name`, `guard_name`))



It's normal to run into SQL errors when you're working with databases. SQLSTATE[42000]: is one of those mistakes that can confuse developers. 1071: The specified key was too long; the maximum key length is 1000 bytes. This error happens when you try to make or change a table with an index that is too big. To keep your database working well and safe, you need to know what this error means and how to fix it. This is a short guide on what causes this error and how to fix it.

Wednesday, 8 August 2018

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long max key length is 767 bytes


Understanding the Error Specified key was too long max key length is 767 bytes

Specified key was too long max key length is 767 bytes occure when developers use Laravel and MySQL databases, they might get the error "Specified key was too long; max key length is 767 bytes." This problem usually happens when Laravel tries to make indexes on string columns during database migrations.

The issue arises because MySQL's InnoDB storage engine has a limit on how long indexes can be. Older versions of MySQL only allow indexes to be 767 bytes long, which is easy to go over when you have long string columns.

The utf8mb4 character set is often used in Laravel apps because it can store emojis and complicated characters from many languages. However, each character in utf8mb4 can take up to 4 bytes, which increases the total index size quickly.

So, if you make a VARCHAR(255) column and add an index or unique constraint, the database might go over the limit for the index size and give you this error when you try to migrate.

.htaccess not working even though allowoverride is enabled

You're not the only one who has had the annoying problem with Apache where your file doesn't work even after you enable it. Who has ...