我试图耙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字节
基础教程推荐
- R语言多元线性回归实例详解 2022-12-15
- go语言的魔幻旅程14-反射 2023-09-05
- R语言学习代码格式一键美化 2022-12-05
- Go语言实现一个Http Server框架(二) Server的抽象 2023-07-25
- R语言关联规则深入详解 2022-11-08
- ruby-on-rails – Nginx支持的Rails应用程序中缺少Content-Length Header 2023-09-20
- golang 自然语言处理工具(gohanlp) 2023-09-05
- R语言使用gganimate创建可视化动图 2022-12-10
- R语言histogram(直方图)的具体使用 2022-10-28
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
