script/generate acts_as_taggable_on_migration
rake db:migrate
原因
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`)
我该怎么办?
这是我的数据库编码:
mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+--------+
7 rows in set (0.00 sec)
最佳答案
这只是一个 MySQL 问题 -
MySQL 有不同的引擎——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 .这些列的数据类型很重要 - 对于 VARCHAR
,它是 3x,所以 VARCHAR(100)
上的索引将占用其中的 300 个字节(因为 100 个字符 * 3 = 300).
为了在达到上限值时容纳一些索引,您可以针对列数据类型的部分定义索引:
CREATE INDEX example_idx ON YOUR_TABLE(your_column(50))
假设 your_column
是 VARCHAR(100)
,上例中的索引只会在前 50 个字符上。搜索超过第 50 个字符的数据将无法使用索引。
关于Mysql::Error: 指定的键太长;最大 key 长度为 1000 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3489041/