title: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "M"
body: <p>So I have a gender column on my user model and it's currently a string, I'd like to change it to a integer and make Male '1', and Female '0' as it's presently Male "M" Female "F". When running this migration:</p>
  
  <pre><code>class ChangeGenderToIntegerOnUser &lt; ActiveRecord::Migration
    def change
      change_column :users, :gender, 'integer USING CAST(gender AS integer)'
    end
  end
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p><strong>error message:</strong></p>
  
  <pre><code>PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "M"
  : ALTER TABLE "users" ALTER COLUMN "gender" TYPE integer USING CAST(gender AS integer)/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec'
  </code></pre>
  
  <p>What should I do to properly change gender to integer?</p>
  
  <p>Thanks in advance!</p>