mysql - Ruby On Rails - Rake 模式 - 最大 key 长度为 767 字节

标签 mysql ruby-on-rails schema innodb max

我正在尝试 rake 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/

相关文章:

MySQL (MariaDB - 10.0.16-MariaDB-1 (Debian) 奇怪的性能问题

ruby-on-rails - Rails 通知系统

java - 在 Java 中使用 XSOM 解析 XSD 架构。如何访问元素和复杂类型

MYSQL关系模式规划

mysql - 获取一行中的预览下一条记录

php - Laravel4 Eloquent 中的连接和动态 `Where`

ruby-on-rails - rails 5.x : add nofollow to all links in 'sanitize'

ruby-on-rails - ruby gem如何在rails环境下工作

node.js - NodeJS Postgres 切换工作模式

mysql - 根据日期检索记录