1

我已经在一个模型(“Stays”)上实现了偏执狂,该模型正在开发中,但不是在 heroku 上的生产中。在 heroku 网站上,我可以看到一个(预计是空的)索引页面,但是当我转到 /stays/new 时,我得到一个错误页面。

检查日志,我发现:

    2017-01-18T03:31:49.546164+00:00 app[web.1]: [d5ce2502-2cb9-4b1d-9888-f2990881bbb4] Completed 500 Internal Server Error in 16ms (ActiveRecord: 4.3ms)
    2017-01-18T03:31:49.547115+00:00 app[web.1]: [d5ce2502-2cb9-4b1d-9888-f2990881bbb4] ActiveModel::UnknownAttributeError (unknown attribute 'deleted_at' for Stay.):
    2017-01-18T03:31:49.547194+00:00 app[web.1]: [d5ce2502-2cb9-4b1d-9888-f2990881bbb4] app/controllers/stays_controller.rb:14:in `new'

在 app/controllers/stays_controller.rb 中,这里是前 15 行。

    class StaysController < ApplicationController
      before_action :set_stay, only: [:show, :edit, :update, :destroy]
      before_action :correct_user, only: [:edit, :update, :destroy]
      before_action :authenticate_user!, except: [:index, :show]

      def index
        @stays = Stay.all.order("created_at DESC")
      end

      def show
      end

      def new
        @stay = current_user.stays.build #Stay.new
      end

在宝石文件中:

gem 'paranoia', '~> 2.2'

在 app/models/stay.rb 中:

class Stay < ApplicationRecord
  belongs_to :user
  acts_as_paranoid
end

自从推到heroku以来,我一直在跑步heroku run rake db:migrate,但没有运气。知道为什么这是在本地进行开发,而不是在 heroku 上进行生产吗?

4

1 回答 1

2

迁移后,您需要重新启动 heroku,因为应用程序正在生产模式下运行。Heroku 在运行任何迁移之前缓存 db 模式。因此,重新启动应用程序将重新缓存模式。

只需运行,您的问题就不会持续存在。

heroku restart
于 2017-01-18T04:06:47.983 回答