简体   繁体   English

在Rails 4.2.6中找不到带有'id'= all迁移错误的表

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

I am getting the following error while running rake db:migrate: 运行rake db:migrate时出现以下错误:

StandardError: An error has occurred, this and all later migrations canceled: StandardError:发生错误,此错误和所有后续迁移被取消:

Couldn't find Report with 'id'=all [WHERE "reports"."deleted_at" IS NULL] 找不到'id'= all [WHERE“ reports”。“ deleted_at” IS NULL]的报告

Theseare my 2 migration files: 这些是我的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

The migrations are fine when running Rail 3.2 and 4.0, but here in 4.2.6, not working. 在运行Rail 3.2和4.0时,迁移很好,但是在4.2.6中无法正常工作。

Please tell me how can I fix this? 请告诉我该如何解决?

Look at the documention for the method find for version > 4.0: 在文档中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]). 按ID查找-这可以是特定ID(1),ID列表(1、5、6)或ID数组([5、6、10])。 If no record can be found for all of the listed ids, then RecordNotFound will be raised. 如果找不到所有列出的ID的记录,则将引发RecordNotFound。 If the primary key is an integer, find by id coerces its arguments using to_i. 如果主键是整数,则按id查找使用to_i强制其参数。

An for version < 4.0: 版本低于4.0的:

Find operates with four different retrieval approaches: Find具有四种不同的检索方法:

  • 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]). 按ID查找-这可以是特定ID(1),ID列表(1、5、6)或ID数组([5、6、10])。 If no record can be found for all of the listed ids, then RecordNotFound will be raised. 如果找不到所有列出的ID的记录,则将引发RecordNotFound。
  • Find first - This will return the first record matched by the options used. 首先查找-这将返回与所用选项匹配的第一条记录。 These options can either be specific conditions or merely an order. 这些选项可以是特定条件,也可以只是订单。 If no record can be matched, nil is returned. 如果没有记录可以匹配,则返回nil。 Use Model.find(:first, *args) or its shortcut Model.first(*args). 使用Model.find(:first,* args)或其快捷方式Model.first(* args)。
  • Find last - This will return the last record matched by the options used. 查找最后-将返回与所使用的选项匹配的最后一条记录。 These options can either be specific conditions or merely an order. 这些选项可以是特定条件,也可以只是订单。 If no record can be matched, nil is returned. 如果没有记录可以匹配,则返回nil。 Use Model.find(:last, *args) or its shortcut Model.last(*args). 使用Model.find(:last,* args)或其快捷方式Model.last(* args)。
  • Find all - This will return all the records matched by the options used. 查找全部-这将返回与使用的选项匹配的所有记录。 If no records are found, an empty array is returned. 如果未找到任何记录,则返回一个空数组。 Use Model.find(:all, *args) or its shortcut Model.all(*args). 使用Model.find(:all,* args)或其快捷方式Model.all(* args)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM