无法找到 table 'id'=Rails 4.2.6 中的所有迁移错误

Couldn't find table with 'id'=all Migration error in Rails 4.2.6

运行 rake db:migrate:

时出现以下错误

StandardError:发生错误,此迁移和所有后续迁移已取消:

找不到 'id'=all [WHERE "reports"."deleted_at" IS NULL]

的报告

这是我的 2 个迁移文件:

Class AddColorToReports < ActiveRecord::Migration
  def self.up
    add_column :reports, :button_color, :string

    Report.find(:all).each do |r|
      r.update_attribute(:color, r.top_stroke_color)
    end
  end

  def self.down
    remove_column :reports, :button_color
  end
end


class AddDeletedAtToReport < ActiveRecord::Migration
  def change
    add_column :reports, :deleted_at, :datetime
  end
end

迁移在 运行 Rail 3.2 和 4.0 时没问题,但在 4.2.6 中无法正常工作。

请告诉我如何解决这个问题?

查看方法 find 版本 > 4.0 的文档:

Find by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). If no record can be found for all of the listed ids, then RecordNotFound will be raised. If the primary key is an integer, find by id coerces its arguments using to_i.

version < 4.0:

Find operates with four different retrieval approaches:

  • 按 ID 查找 - 这可以是特定 ID (1)、ID 列表 (1, 5, 6), 或 id 数组 ([5, 6, 10])。如果找不到记录 所有列出的 id,然后将引发 RecordNotFound。
  • 首先查找 - 这将 return 与选项匹配的第一条记录 用过的。这些选项可以是特定条件或仅仅是 命令。如果没有记录可以匹配,nil 是 returned。采用 Model.find(:first, *args) 或其快捷方式 Model.first(*args).
  • 查找最后 - 这将 return 与选项匹配的最后一条记录 用过的。这些选项可以是特定条件或仅仅是 命令。如果没有记录可以匹配,nil 是 returned。采用 Model.find(:last, *args) 或其快捷方式 Model.last(*args).
  • 查找所有 - 这将 return 与选项匹配的所有记录 用过的。如果未找到任何记录,则会 return 编辑一个空数组。采用 Model.find(:all, *args) 或其快捷方式 Model.all(*args).