Home >Database >Mysql Tutorial >How to Solve MySQL Error: 'Specified key was too long; max key length is 1000 bytes'?
Troubleshooting "Mysql::Error: Specified key was too long; max key length is 1000 bytes"
When attempting to run the following commands:
script/generate acts_as_taggable_on_migration rake db:migrate
you may encounter the error:
Mysql::Error: Specified key was too long; max key length is 1000 bytes: CREATE INDEX `index_taggings_on_taggable_id_and_taggable_type_and_context` ON `taggings` (`taggable_id`, `taggable_type`, `context`)
Cause
This error occurs due to restrictions imposed by MySQL's storage engines on the size of indexes. MyISAM engines, commonly used with Ruby on Rails, limit index sizes to 1,000 bytes.
Solution
To resolve this issue, consider the following strategies:
CREATE INDEX example_idx_id ON YOUR_TABLE(taggable_id) CREATE INDEX example_idx_type ON YOUR_TABLE(taggable_type)
Additional Configuration
As indicated by your database encoding settings, your database is configured to use latin1 character encoding. This may limit the effectiveness of indexes on columns using UTF-8 encoding. To improve index performance, consider converting your database to UTF-8 encoding.
The above is the detailed content of How to Solve MySQL Error: 'Specified key was too long; max key length is 1000 bytes'?. For more information, please follow other related articles on the PHP Chinese website!