Search code examples
mysqlruby-on-rails

Removing multiple columns in table within a database. (rails)


I am having trouble removing multiple columns in my local database.

My table name is 'customers' and within that table the two columns I am trying to remove are 'phone' and 'fax'

I've been trying something along the lines of this

class CustomerCleanup < ActiveRecord::Migration
  def change_table(:customers) do |t|
      t.remove :fax, :phone
    end
  end
end

but I continue to get a syntax error stating 'unexpected tSYMBEG expecting ')'

I've looked at the examples in Here....and I've tried this as well only to get the same error

class CustomerCleanup < ActiveRecord::Migration
  def change_table(:customers) do |t|
      t.remove :fax
      t.remove :phone
    end
  end
end

Would anyone know what i'm doing wrong here?


Solution

  • Have you tried:

    def change
      remove_column :customers, :fax
      remove_column :customers, :phone
    end
    

    In case you are using rails version lower than 3.x

    def self.up
     remove_column :customers, :fax
     remove_column :customers, :phone
    end
    
    def self.down
      # do something on rollback here or just do nothing
    end