How do I change column type in Heroku? How do I change column type in Heroku? heroku heroku

How do I change column type in Heroku?


Do the following:

  1. rename the column A
  2. create the new column B as date
  3. move the data from A to B
  4. remove A

In other words

def self.up  rename_column :contacts, :date_entered, :date_entered_string  add_column :contacts, :date_entered, :date  Contact.reset_column_information  Contact.find_each { |c| c.update_attribute(:date_entered, c.date_entered_string) }   remove_column :contacts, :date_entered_stringend


This is a modified and tested version of Simone Carletti's solution

class ModifyContacts < ActiveRecord::Migration  def self.up    rename_column :contacts, :date_entered, :date_entered_string    add_column :contacts, :date_entered, :date    Contact.reset_column_information    Contact.find(:all).each { |contact| contact.update_attribute(:date_entered, contact.date_entered_string) }    remove_column :contacts, :date_entered_string  endend