title: How to rename a column and change its type by migration same time
body: <p>In my <code>general_exams</code> table, I have a column named <code>semester</code>, type is <code>string</code>. Now I want to change its name to <code>semester_id</code>, type is <code>integer</code>. I have read about migration and it has available transformations:</p>
  
  <ul>
  <li>rename_column(table_name, column_name, new_column_name): Renames a column but keeps the type and content.</li>
  <li>change_column(table_name, column_name, type, options): Changes the column to a different type using the same parameters as add_column.</li>
  </ul>
  
  <p>So, I create my migration file like this:</p>
  
  <pre><code>class RenameSemesterFromGeneralExams &lt; ActiveRecord::Migration
  
    def change
      rename_column :general_exams, :semester, :semester_id
      change_column :general_exams, :semester_id, :integer
    end
  end
  </code></pre>
  
  <p>But, when I run <code>rake db:migrate</code>, it has error:</p>
  
  <pre><code>==  RenameSemesterFromGeneralExams: migrating =================================
  -- rename_column(:general_exams, :semester, :semester_id)
     -&gt; 0.0572s
  -- change_column(:general_exams, :semester_id, :integer)
  rake aborted!
  An error has occurred, this and all later migrations canceled:
  
  PG::Error: ERROR:  column "semester_id" cannot be cast to type integer
  : ALTER TABLE "general_exams" ALTER COLUMN "semester_id" TYPE integer
  </code></pre>
  
  <p>In my table GeneralExam, I destroyed all data.
  So, anyone can tell me how can I do that? Or I must create two migration files?</p>