venkat
venkat

Reputation: 836

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:

StandardError: An error has occurred, this and all later migrations canceled:

Couldn't find Report with 'id'=all [WHERE "reports"."deleted_at" IS NULL]

Theseare my 2 migration files:

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.

Please tell me how can I fix this?

Upvotes: 0

Views: 606

Answers (1)

Roman Kiselenko
Roman Kiselenko

Reputation: 44380

Look at the documention for the method find for version > 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.

An for version < 4.0:

Find operates with four different retrieval approaches:

  • 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.
  • 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. Use Model.find(:first, *args) or its shortcut 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. Use Model.find(:last, *args) or its shortcut 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).

Upvotes: 2

Related Questions