在Heroku中引导rails服务器时未定义的方法add_column

时间:2014-08-03 22:12:51

标签: ruby-on-rails ruby heroku rails-activerecord heroku-postgres

当我尝试在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也可以正常工作而不会抛出错误。知道这可能是什么吗?

1 个答案:

答案 0 :(得分:1)

如果要编写迁移,则应继承ActiveRecord::Migration。不要忘记updownchange方法:

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