簡體   English   中英

在Rails 4.2.6中找不到帶有'id'= all遷移錯誤的表

[英]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的方法:

按ID查找-這可以是特定ID(1),ID列表(1、5、6)或ID數組([5、6、10])。 如果找不到所有列出的ID的記錄,則將引發RecordNotFound。 如果主鍵是整數,則按id查找使用to_i強制其參數。

版本低於4.0的:

Find具有四種不同的檢索方法:

  • 按ID查找-這可以是特定ID(1),ID列表(1、5、6)或ID數組([5、6、10])。 如果找不到所有列出的ID的記錄,則將引發RecordNotFound。
  • 首先查找-這將返回與所用選項匹配的第一條記錄。 這些選項可以是特定條件,也可以只是訂單。 如果沒有記錄可以匹配,則返回nil。 使用Model.find(:first,* args)或其快捷方式Model.first(* args)。
  • 查找最后-將返回與所使用的選項匹配的最后一條記錄。 這些選項可以是特定條件,也可以只是訂單。 如果沒有記錄可以匹配,則返回nil。 使用Model.find(:last,* args)或其快捷方式Model.last(* args)。
  • 查找全部-這將返回與使用的選項匹配的所有記錄。 如果未找到任何記錄,則返回一個空數組。 使用Model.find(:all,* args)或其快捷方式Model.all(* args)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM