我在一個git分支上,試圖在銷燬分支之前回滾兩個遷移。最近的遷移將一列添加到我想要保留的表中(並且哪些是master的一部分,而不是要刪除的分支),因此刪除整個表並不是解決方案(除非我必須重新創建它)。無論如何,我一定犯了錯誤,因爲當我試圖從scores表中刪除apple_id列時,我得到了這個中止錯誤。索引名稱太長,無法回滾遷移
這是我想回滾
add_column :scores, :apple_id, :integer
但是遷移,錯誤信息(見下文)是指的是我與原遷移(主分支的一部分)中創建的索引是創建表格
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
更新:閱讀這太問題How do I handle too long index names in a Ruby on Rails migration with MySQL?,我得到了這個問題的根源一些更多的信息,但不知道如何解決它。 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
而且,爲什麼我沒有要刪除該表是我不確定它可能在重新創建因爲)的主要部分是造成什麼問題的原因遷移在分支主機上創建,而在分支上添加列,b)我不確定如何處理刪除的表的遷移文件?因爲它是我創建的第四張(大約10張)桌子,我不知道如何運行它,只能再次運行它。
什麼版本的Rails,您使用的?我用Rails v3.1.0從零開始重新創建了一個項目,但回滾效果不錯。我也在使用PG v9.0.1。當我創建一個索引爲'add_index:scores,[:user_id,:created_at,:funded,:started]'時,索引名稱爲'index_scores_on_user_id_and_created_at_and_funded_and_started'。 – 2013-03-15 22:39:26
如果您不想從頭開始刪除並重新創建數據庫,我強烈建議您在數據庫控制檯中手動刪除索引。而且,你可以在回滾之前在這裏粘貼你的完整遷移'AddAppleIdColumnToScores'和你的schema.rb嗎? – 2013-03-15 22:40:12
您是否嘗試使用純SQL刪除索引? – 2013-03-18 09:24:18