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. You'...