Mysql::Error: Specified key was too long; max key length is 1000 bytes

This is solely a MySQL issue –

MySQL has different engines – MyISAM, InnoDB, Memory…

MySQL has different limits on the amount of space you can use to define indexes on column(s) – for MyISAM it’s 1,000 bytes; it’s 767 for InnoDB. And the data type of those columns matters – for VARCHAR, it’s 3x so an index on a VARCHAR(100) will take 300 of those bytes (because 100 characters * 3 = 300).

To accommodate some indexing when you hit the ceiling value, you can define the index with regard to portions of the column data type:

CREATE INDEX example_idx ON YOUR_TABLE(your_column(50))

Assuming that your_column is VARCHAR(100), the index in the example above will only be on the first 50 characters. Searching for data beyond the 50th character will not be able to use the index.

Leave a Comment