索引名称太长,无法回滚迁移

我在git分支上并试图在销毁分支之前回滚两次迁移。 最近的迁移会向我要保留的表添加一列(并且它是master的一部分,而不是要删除的分支),因此删除整个表不是解决方案(除非我必须再次重新创建它)。 无论如何,我一定做错了,因为当我试图从得分表中删除apple_id列时,我得到了这个中止错误。

这是我正在尝试回滚的迁移

add_column :scores, :apple_id, :integer 

但是,错误消息(参见下文)是指我使用创建表的原始迁移(master分支的一部分)创建的索引

 add_index :scores, [:user_id, :created_at, :funded, :started] 

你能建议我做什么吗?

 == AddAppleidColumnToScores: reverting ======================================= -- remove_column("scores", :apple_id) rake aborted! An error has occurred, this and all later migrations canceled: Index name 'temp_index_altered_scores_on_user_id_and_created_at_and_funded_and_started' on table 'altered_scores' is too long; the limit is 64 characters 

更新:阅读此SO问题如何在使用MySQL的Ruby on Rails迁移中处理太长的索引名称? ,我得到了一些关于问题根源的更多信息,但不知道如何解决它。 sql和postgres都有64个字符限制

 Index name 'index_studies_on_user_id_and_university_id_and_subject_\ name_id_and_subject_type_id' on table 'studies' is too long; \ the limit is 64 characters 

我所提到的问题的接受答案是说给索引起一个名字,虽然我现在还不确定我是怎么做的,因为我正在尝试回滚。

 add_index :studies, ["user_id", "university_id", \ "subject_name_id", "subject_type_id"], :unique => true, :name => 'my_index' 

更新:响应评论,我正在使用Rails 3.2.12。 这是添加列的迁移

 class AddAppleidColumnToScores < ActiveRecord::Migration def change add_column :scores, :apple_id, :integer end end 

此外,我不想放弃表的原因是我不确定它可能会在重新创建时出现什么问题,因为a)主要部分是在分支主机上创建的,而一个列添加在分支上而b)我不确定如何处理删除表的迁移文件? 因为它是我创建的第四个(大约10个)表格,所以我不知道如何再次运行它。

你可以复制/粘贴你的迁移吗?

这是我的:

 class AddAppleIdColumnToScores < ActiveRecord::Migration def self.up add_column :scores, :apple_id, :integer add_index :scores, [:user_id, :created_at, :funded, :started] end def self.down # delete index MySql way # execute "DROP INDEX index_scores_on_user_id_and_created_at_and_funded_and_started ON scores" # delete index Postgresql way # execute "DROP INDEX index_scores_on_user_id_and_created_at_and_funded_and_started" # delete index Rails way / not necessary if you remove the column # remove_index :scores, [:user_id, :created_at, :funded, :started] remove_column :scores, :apple_id end end