title: How do I change column type in Heroku?
body: <p>I am trying to rake the db:migrations into my heorku instance and I get an error.  The FAQ described my error as below:</p>
  
  <blockquote>
    <p>Cannot change column type</p>
    
    <p>Example: PGError: ERROR: column
    “verified_at” cannot be cast to type
    “date”</p>
    
    <p>Cause: PostgreSQL doesn’t know how to
    cast all the rows in that table to the
    specified type. Most likely it means
    you have an integer or a string in
    that column.</p>
    
    <p>Solution: Inspect your records and
    make sure they can be converted to the
    new type. Sometimes it’s easier to
    just avoid using change_column,
    renaming/creating a new column
    instead.</p>
  </blockquote>
  
  <p>How do I change this migration now.  This is the problem that I have.  For my Contacts table, I created the following:</p>
  
  <pre><code>  t.string :date_entered
  </code></pre>
  
  <p>In a later migration, I do the following:</p>
  
  <pre><code> change_column :contacts, :date_entered, :date
  </code></pre>
  
  <p>This change_column appears to be the problem.</p>
  
  <p>Should I...change by hand that migration?  Is there a way I can clean the data in my tables (I didn't know Heroku would recognize the data in the table because I'm doing a rake).</p>
  
  <p>I obviously need to change this value and it is used throughout my application.  Thanks.</p>
  
  <p><strong>This is what I am trying...thoughts?</strong></p>
  
  <pre><code>def self.up
    #change_column :contacts, :date_entered, :date
    #this fails in postgres, so trying the same outcome 
  
    rename_column :contacts, :date_entered, :date_entered_old
    add_column :contacts, :date_entered, :date
    remove_column :contacts, :date_entered_old
  end
  
  def self.down
    add_column :contacts, :date_entered_old
    remove_column :contacts, :date_entered
    rename_column :contacts, :date_entered_old, :date_entered
  end
  </code></pre>