ruby-on-rails – 索引名称太长 – Rails 3
发布时间:2020-12-17 02:37:03 所属栏目:百科 来源:网络整理
导读:我正在尝试运行此迁移: class RemoveClientFromSalesteam ActiveRecord::Migration change_table :sales_teams do |t| t.remove :client_id endend 这是我得到的错误: rake db:migrate-- change_table(:sales_teams)rake aborted!An error has occurred,th
我正在尝试运行此迁移:
class RemoveClientFromSalesteam < ActiveRecord::Migration change_table :sales_teams do |t| t.remove :client_id end end 这是我得到的错误: rake db:migrate -- change_table(:sales_teams) rake aborted! An error has occurred,this and all later migrations canceled: Index name 'temp_index_altered_sales_teams_on_client_priority_and_personal_priority' on table 'altered_sales_teams' is too long; the limit is 64 characters Tasks: TOP => db:migrate (See full trace by running task with --trace) 这就是我的schema.rb的样子: create_table "sales_teams",:force => true do |t| t.string "name" t.integer "firm_id" t.boolean "client_priority" t.boolean "personal_priority" t.datetime "created_at",:null => false t.datetime "updated_at",:null => false t.integer "client_id" end add_index "sales_teams",["client_id"],:name => "index_sales_teams_on_client_id" add_index "sales_teams",["client_priority","personal_priority"],:name => "index_sales_teams_on_client_priority_and_personal_priority" add_index "sales_teams",["name","firm_id"],:name => "index_sales_teams_on_name_and_firm_id" 思考? 谢谢. 解决方法
删除索引,删除列,然后重新添加索引:
def up remove_index :sales_teams,:column => [ :client_priority,:personal_priority ] remove_column :sales_teams,:client_id add_index :sales_teams,[ :client_priority,:personal_priority ] end 我猜你正在使用SQLite,大多数数据库支持真正的ALTER TABLE操作来删除列,但SQLite强制你复制表(和索引),删除表,然后将所有内容复制回来; Rails SQLite驱动程序在幕后处理这个问题,但显然不知道标识符长度限制. 如有必要,还可以使用:name选项指定 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |