Im trying to rake db:schema:load but I get the error
Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX
From what I understand is that InnoDB only allows a max of 767 bytes in their index... And if you're using utf-8 it should be divided by 3.
But when i try to set a maximum of 100 characters (its not even close to 767) in the schema.rb the error still occurs...
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 }
Error
-- 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)
What am I missing?
I see two problems in your code:
limit parameter should be called lengthlength parameter should be a hash that specifies the length for both columns: :length => { :slug => 200, :sluggable_type => 30 }Check out the documentation: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_index-label-Creating+an+index+with+specific+key+length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With