-2
我已成功完成三次遷移。如何回滾遷移?
20150109133619_add_items.rb:
class AddItems < ActiveRecord::Migration
def change
create_table :pros do |t|
t.string :titlerr
t.text :description
t.string :image_url
t.decimal :price
t.timestamps
end
end
end
20150109134955_add_col.rb:
class AddCol < ActiveRecord::Migration
def change
add_column :pros, :fieldname, :string
end
end
20150109162301_del_col.rb:
class DelCol < ActiveRecord::Migration
def change
remove_column :pros, :fieldname
end
end
現在我需要在遷移之前20150109134955.我回滾狀態做了以下事情:
rake db:rollback
結果如下消息:
== DelCol: reverting =========================================================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
remove_column is only reversible if given a type./home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/migration/command_recorder.rb:128:in `invert_remove_column'
/home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/migration/command_recorder.rb:66:in `inverse_of'
........
........
........
/home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:126:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
我的第二次嘗試:
rake db:rollback VERSION=20150109134955
結果如下消息:
== DelCol: reverting =========================================================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
remove_column is only reversible if given a type./home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/migration/command_recorder.rb:128:in `invert_remove_column'
/home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/migration/command_recorder.rb:66:in `inverse_of'
.....
.....
.....
/home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:126:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
你有沒有嘗試像20150109162301這樣的錯誤信息建議添加',:string'?那麼發生了什麼? – 2015-01-09 20:31:18
請嘗試運行'rake db:rollback -trace'並查看完整跟蹤,並在此處發佈跟蹤。 – 2015-01-09 20:31:54
請閱讀錯誤信息。它試圖幫助你。 – ptd 2015-01-09 20:33:27