我试图耙 db:schema:load 但我收到错误
Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX
据我了解,InnoDB 的索引中最多只允许 767 个字节……如果您使用的是 utf-8,则应除以 3。
但是当我尝试在 schema.rb 中设置最多 100 个字符(它甚至不接近 767 个)时,错误仍然发生......
schema.rb
add_index "friendly_id_slugs", ["slug", "sluggable_type"], :name => "index_friendly_id_slugs_on_slug_and_sluggable_type", :unique => true, :length => { :name => 100, :slug => 100, :sluggable_type => 40 }
错误
-- add_index("friendly_id_slugs", ["slug", "sluggable_type"], {:name=>"index_friendly_id_slugs_on_slug_and_sluggable_type", :unique=>true, :length=>{:name=>100, :slug=>100, :sluggable_type=>40}})
rake aborted!
Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_friendly_id_slugs_on_slug_and_sluggable_type` ON `friendly_id_slugs` (`slug`, `sluggable_type`)
MySQL
Your MySQL connection id is 1838
Server version: 5.5.22-0ubuntu1-log (Ubuntu)
我错过了什么?
最佳答案
我在您的代码中看到两个问题:
limit
参数应该被称为 length
length
参数应该是指定两列长度的散列: :length => { :slug => 200, :sluggable_type => 30 }
查看文档: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_index-label-Creating+an+index+with+specific+key+length 。
关于mysql - Ruby On Rails - Rake 模式 - 最大 key 长度为 767 字节,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10931307/