将列添加到表Rails 3后出现未知属性错误

cel*_*iko 4 ruby ruby-on-rails migrate heroku

我对Rails非常新,我完全被难倒了.我真的只需要这个工作,因为它是另一个更大的Javascript项目的一部分,并且Rails部分刚刚倾倒在我身上.我必须在page_events表中添加列(添加的列是student_id,student_name和survey_name),所以我进行了迁移,rake db:migrate,一切顺利.这是我的schema.db的相关部分

create_table "page_events", :force => true do |t|
    t.string   "page"
    t.integer  "num_focus",       :default => 0
    t.integer  "num_distracted",  :default => 0
    t.datetime "created_at",                     :null => false
    t.datetime "updated_at",                     :null => false
    t.integer  "time_focused",    :default => 0
    t.integer  "time_distracted", :default => 0
    t.integer  "total_time",      :default => 0
    t.string   "session_id"
    t.string   "student_id"
    t.string   "student_name"
    t.string   "survey_name"
end
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将数据发布到page_events页面时,服务器响应500内部服务器错误

ActiveRecord::UnknowAttributeError (unknown attribute: student_id):app/controllers/page_events_controller.rb:51 in 'new'
Run Code Online (Sandbox Code Playgroud)

我尝试发布数据,除了没有student_name,student_id或survey_name,它工作正常.没有500错误,我发送的数据显示在page_events索引上,就像它应该的那样.我检查了一遍,无法找到任何结论,我非常紧张打破它因为我说我对Rails很新.我看到一些建议是重新生成模型,但我不知道这是否有帮助.我可以在代码中找到唯一具有显式表名和列的地方在schema.db中并且如上所述,似乎是正确的.请帮忙...

我正在部署到一个heroku应用程序,我不知道这是否有所作为...

Joh*_*non 12

完成迁移后,您需要执行一个操作,heroku restart因为应用程序在生产模式下运行,并且在迁移运行之前将缓存数据库模式.重新启动应用程序将重新缓存架构.很可能,你的应用程序已经被Heroku重新启动,因为你发布了这个问题,现在问题已经消失了.