Answer the question
In order to leave comments, you need to log in
Error creating index in Mysql2 database - how to specify the length of a composite key?
I must say right away that there is no error in Sqlite.
I decided to add the "rolify" gem as a permission delimiter in conjunction with devise and cancancan. Everything was OK in the development environment, but when I uploaded it to the server, an error was found:
-- add_index("roles", ["name", "resource_type", "resource_id"], {:name=>"index_roles_on_name_and_resource_type_and_resource_id"})
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 1000 bytes: CREATE INDEX `index_roles_on_name_and_resource_type_and_resource_id` ON `roles` (`name`, `resource_type`, `resource_id`)
-- add_index("roles", ["name", "resource_type", "resource_id"], {:name=>"index_roles_on_name_and_resource_type_and_resource_id", :length=>{:name=>100, :resource_type=>20, :resource_id=>11}})
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 1000 bytes: CREATE INDEX `index_roles_on_name_and_resource_type_and_resource_id` ON `roles` (`name`, `resource_type`, `resource_id`)
#execute "CREATE INDEX `index_roles_on_name_and_resource_type_and_resource_id` ON `roles` (`name`(100), `resource_type`(20), `resource_id`(11))"
Answer the question
In order to leave comments, you need to log in
What version of Ruby (and RoR)?
Example from APIDoc:
add_index(:accounts, [:name, :surname], name: 'by_name_surname', length: {name: 10, surname: 15})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question