当我尝试在heroku中运行rails时,我收到了这个奇怪的错误:undefined method 'add_column' for #<Class:0x007f7a6a73cf30> (NoMethodError)
。它似乎在以下迁移中抛出了这个错误:
class AddPresentationAttributesToPosts < ActiveRecord::Base
add_column :presentations, :ticker, :string
add_column :presentations, :action, :string
add_column :presentations, :thesis, :string
add_column :presentations, :slideshare_url, :string
end
但是,所有这些都在本地工作,heroku run rake db:migrate
也可以正常工作而不会抛出错误。知道这可能是什么吗?
答案 0 :(得分:1)
如果要编写迁移,则应继承ActiveRecord::Migration
。不要忘记up
,down
和change
方法:
class AddPresentationAttributesToPosts < ActiveRecord::Migration
def change
add_column :presentations, :ticker, :string
add_column :presentations, :action, :string
add_column :presentations, :thesis, :string
add_column :presentations, :slideshare_url, :string
end
end