2

我想在我的索引表中添加另一个索引列,但是收到的表索引太长;限制为 64 个字符。顺便说一句,Rails 3 和 MySQL DB。

当前架构如下:

  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"

我正在尝试运行以下迁移来添加索引:

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

但是在尝试 rake 时得到以下信息(简而言之):

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
[...]
4

1 回答 1

4

尝试这个

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
于 2013-02-23T03:24:52.140 回答