title: How to alter column type from character varying to integer using sqlalchemy-migrate
body: <p>I'm using sqlalchemy-migrate to alter the type of one of the columns in a table in a Postgre SQL database. The upgrade script I'm using is:</p>
  
  <pre class="lang-python prettyprint-override"><code># -*- cofing: utf-8 -*-
  
  from sqlalchemy import MetaData, Table, Column, String, Integer
  from migrate import changeset
  
  
  metadata = MetaData()
  
  
  def upgrade(migrate_engine):
      # ALTER TABLE courses ALTER COLUMN number SET DATA TYPE character varying;
      metadata.bind = migrate_engine
      courses = Table('courses', metadata, Column("number", Integer), extend_existing=True)
      courses.c.number.alter(type=String)
  
  
  def downgrade(migrate_engine):
      # ALTER TABLE courses ALTER COLUMN number SET DATA TYPE integer;
      metadata.bind = migrate_engine
      courses = Table('courses', metadata, Column("number", String), extend_existing=True)
      courses.c.number.alter(type=Integer, cast='numeric')
  </code></pre>
  
  <p>The upgrade part seems to work but the downgrade always fails with the following error:</p>
  
  <pre><code>sqlalchemy.exc.ProgrammingError: (ProgrammingError) column "number" cannot be cast to type integer
  '\nALTER TABLE courses ALTER COLUMN number TYPE INTEGER' {}
  </code></pre>
  
  <p>Now, if I were using plain SQL I could use <code>ALTER TABLE courses ALTER COLUMN number TYPE INTEGER USING number::numeric</code> to alter the column type back from <code>character varying</code> to <code>integer</code>, but I don't know how to achieve that using sqlalchemy-migrate.</p>
  
  <p>Is there a way to force sqlalchemy to include <code>USING number::numeric</code> in the <code>ALTER</code> clause? or is there another way to avoid the error I posted above?</p>
  
  <p>I appreciate your help.</p>