title: heroku: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “”
body: <p>I have a currency(ccy) column on my event model and it's currently a string, I'd like to change it to a integer.</p>
  
  <p>Although it works on my local environment, the following error was displayed when I try <code>heroku run rake db:migrate</code> to heroku.</p>
  
  <pre><code>rake aborted!
  StandardError: An error has occurred, this and all later migrations canceled:
  
  PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: ""
  : ALTER TABLE "events" ALTER COLUMN "ccy" TYPE integer USING CAST(ccy AS integer)
  </code></pre>
  
  <p>The migration file as below.</p>
  
  <pre><code>class ChangeCcyToEvents &lt; ActiveRecord::Migration
    def change
      change_column :events, :ccy, 'integer USING CAST(ccy AS integer)'
    end
  end
  </code></pre>
  
  <p>I found the similar question <a href="https://stackoverflow.com/questions/20715190/pginvalidtextrepresentation-error-invalid-input-syntax-for-integer-m">PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: &quot;M&quot;</a>, so I changed migration file as below. But the result is the same.</p>
  
  <pre><code>class ChangeCcyToEvents &lt; ActiveRecord::Migration
    def change
      Event.where(ccy: '').update_all(ccy: '')
      change_column :events, :ccy, 'integer USING CAST(ccy AS integer)'
    end
  end
  </code></pre>
  
  <p>There is no value in all <code>ccy</code> column so far.</p>
  
  <p>It would be appreciated if you could give me any advice.</p>