Reputation: 59
I want to add another index column to my index table,but receive an index on table is too long; the limit is 64 characters. Rails 3 and MySQL DB by the way.
The current schema is as follows:
create_table "admin_users_projects", :force => true do |t|
t.integer "admin_user_id"
t.integer "project_id"
end
add_index "admin_users_projects", ["admin_user_id", "project_id"], :name => "index_admin_users_projects_on_admin_user_id_and_project_id"
I am trying to run the following migration to add the index:
class AddIndexToAdminUsersProjects < ActiveRecord::Migration
def change
add_index :index_admin_users_projects_on_admin_user_id_and_project_id, :admin_users_project_id
end
end
But get the following when attempting the rake (in short):
Larrys-MacBook-Pro:scrumtool larrydavid$ rake db:migrate
== AddIndexToAdminUsersProjects: migrating ===================================
-- add_index(:index_admin_users_projects_on_admin_user_id_and_project_id, :admin_users_project_id)
rake aborted!
An error has occurred, all later migrations canceled:
Index name 'index_index_admin_users_projects_on_admin_user_id_and_project_id_on_admin_users_project_id' on table 'index_admin_users_projects_on_admin_user_id_and_project_id' is too long; the limit is 64 characters
[...]
Upvotes: 2
Views: 269
Reputation: 5617
Try this
class AddIndexToAdminUsersProjects < ActiveRecord::Migration
def change
add_index :admin_users_project, [:admin_users_id, :project_id], :name => 'index_admin_projects_on_admin_and_project'
end
end
Upvotes: 4