我试图耙db:schema:load但我得到了错误Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX 据我了解,InnoDB的索引中最多只允许767个字节…如果您使用的是utf-8,则应将...

我试图耙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)
我想念什么?
解决方法:
我在您的代码中看到两个问题:
>极限参数应称为长度
>在多列索引中,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模式-最大密钥长度为767字节


- 汇编语言程序设计之根据输入改变屏幕颜色的代码 2023-07-06
- R语言绘图数据可视化pie chart饼图 2022-12-10
- Swift超详细讲解指针 2023-07-08
- Golang http.Client设置超时 2023-09-05
- Ruby 迭代器知识汇总 2023-07-23
- R语言-如何切换科学计数法和更换小数点位数 2022-11-23
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
- Ruby的字符串与数组求最大值的相关问题讨论 2023-07-22
- Go Web开发进阶实战(gin框架) 2023-09-06
- R语言关于二项分布知识点总结 2022-11-30