我试图耙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字节
基础教程推荐
- Go web部署报错panic: listen tcp xxxxxxx:8090: bind: cannot assign requested address 2023-09-05
- R语言数可视化Split violin plot小提琴图绘制方法 2022-12-10
- R包ggtreeExtra绘制进化树 2022-12-14
- swift版webview加载网页进度条效果 2023-07-05
- ruby-on-rails-使用Nginx的Rails的多阶段环境 2023-09-21
- swift 字符串String的使用方法 2023-07-05
- asm基础——汇编指令之in/out指令 2023-07-06
- UEFI开发基础HII代码示例 2023-07-07
- R语言-如何将科学计数法表示的数字转化为文本 2022-11-23
- R语言基于Keras的MLP神经网络及环境搭建 2022-12-10