[英]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具有四種不同的檢索方法:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.