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

我试图耙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字节

基础教程推荐