Remove and Add columns to the database the Rails 2.0 way

Use change_table and its sub methods rather than remove_column and add_column

Resource

#example
class AddCategoryIdToPosts < ActiveRecord::Migration
  def self.up
    change_table :posts do |t|
      t.references :category
    end
  end

  def self.down
    change_table :posts do |t|
      t.remove_references :category
    end
  end
end
# another exmample. note remove_integer doesn't work. just use plain old 'remove'
class AddRedirectLocaleToPages < ActiveRecord::Migration
  def self.up
    change_table :pages do |t|
      t.integer :redirect_locale, :default => 0
    end
  end

  def self.down
    change_table :pages do |t|
      t.remove :redirect_locale, :default => 0
    end
  end
end

Comments