How do I change column type in Heroku?
Do the following:
- rename the column A
- create the new column B as date
- move the data from A to B
- 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