vendredi 17 juillet 2015

Rails migration delete row

I'm trying to run a migration to delete two rows in the database. Here's the migration file ...

class RemoveMenuItem < ActiveRecord::Migration
  def up
    MenuItem.delete(name: "Validation Settings")
    MenuItem.delete(name: "Identifier Lookup")
  end

  def down
    MenuItem.create(name: "Validation Settings", type: "MenuItem", actionable_item_id: 89, actionable_items_count: 0, sequence: 20)
    MenuItem.create(name: "Identifier Lookup", type: "MenuItem", actionable_item_id: 89, actionable_items_count: 0, sequence: 30)
  end
end

... but I'm getting this error ...

PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "id"
LINE 1: ...ERE "actionable_items"."type" IN ('MenuItem') AND "id"."name...
                                                             ^
: DELETE FROM "actionable_items" WHERE "actionable_items"."type" IN ('MenuItem') AND "id"."name" = 'Validation Settings'/Users/kweihe/.rvm/gems/ruby-2.1.6/gems/activerecord-3.2.22/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:in `async_exec'

Aucun commentaire:

Enregistrer un commentaire