title: Alembic: alter column type with USING
body: <p>I'm attempting to use alembic to convert a SQLAlchemy PostgreSQL <code>ARRAY(Text)</code> field to a <code>BIT(varying=True)</code> field for one of my table columns.</p>
  <p>The column is currently defined as:</p>
  <pre class="lang-py prettyprint-override"><code>cols = Column(ARRAY(TEXT), nullable=False, index=True)
  </code></pre>
  <p>I want to change it to:</p>
  <pre class="lang-py prettyprint-override"><code>cols = Column(BIT(varying=True), nullable=False, index=True)
  </code></pre>
  <p>Changing column types doesn't seem to be supported by default, so I'm editing the alembic script by hand. This is what I have currently:</p>
  <pre class="lang-py prettyprint-override"><code>def upgrade():
      op.alter_column(
          table_name='views',
          column_name='cols',
          nullable=False,
          type_=postgresql.BIT(varying=True)
      )
  
  
  def downgrade():
      op.alter_column(
          table_name='views',
          column_name='cols',
          nullable=False,
          type_=postgresql.ARRAY(sa.Text())
      )
  </code></pre>
  <p>However, running this script gives the error:</p>
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File &quot;/home/home/.virtualenvs/deus_lex/bin/alembic&quot;, line 9, in &lt;module&gt;
      load_entry_point('alembic==0.7.4', 'console_scripts', 'alembic')()
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/config.py&quot;, line 399, in main
      CommandLine(prog=prog).main(argv=argv)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/config.py&quot;, line 393, in main
      self.run_cmd(cfg, options)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/config.py&quot;, line 376, in run_cmd
      **dict((k, getattr(options, k)) for k in kwarg)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/command.py&quot;, line 165, in upgrade
      script.run_env()
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/script.py&quot;, line 382, in run_env
      util.load_python_file(self.dir, 'env.py')
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/util.py&quot;, line 242, in load_python_file
      module = load_module_py(module_id, path)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/compat.py&quot;, line 79, in load_module_py
      mod = imp.load_source(module_id, path, fp)
    File &quot;./scripts/env.py&quot;, line 83, in &lt;module&gt;
      run_migrations_online()
    File &quot;./scripts/env.py&quot;, line 76, in run_migrations_online
      context.run_migrations()
    File &quot;&lt;string&gt;&quot;, line 7, in run_migrations
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/environment.py&quot;, line 742, in run_migrations
      self.get_context().run_migrations(**kw)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/migration.py&quot;, line 305, in run_migrations
      step.migration_fn(**kw)
    File &quot;/home/home/deus_lex/winslow/scripts/versions/2644864bf479_store_caselist_column_views_as_bits.py&quot;, line 24, in upgrade
      type_=postgresql.BIT(varying=True)
    File &quot;&lt;string&gt;&quot;, line 7, in alter_column
    File &quot;&lt;string&gt;&quot;, line 1, in &lt;lambda&gt;
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/util.py&quot;, line 387, in go
      return fn(*arg, **kw)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/operations.py&quot;, line 470, in alter_column
      existing_autoincrement=existing_autoincrement
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/ddl/impl.py&quot;, line 147, in alter_column
      existing_nullable=existing_nullable,
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/alembic/ddl/impl.py&quot;, line 105, in _exec
      return conn.execute(construct, *multiparams, **params)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 729, in execute
      return meth(self, multiparams, params)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py&quot;, line 69, in _execute_on_connection
      return connection._execute_ddl(self, multiparams, params)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 783, in _execute_ddl
      compiled
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 958, in _execute_context
      context)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 1159, in _handle_dbapi_exception
      exc_info
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py&quot;, line 199, in raise_from_cause
      reraise(type(exception), exception, tb=exc_tb)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 951, in _execute_context
      context)
    File &quot;/home/home/.virtualenvs/deus_lex/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py&quot;, line 436, in do_execute
      cursor.execute(statement, parameters)
  sqlalchemy.exc.ProgrammingError: (ProgrammingError) column &quot;cols&quot; cannot be cast automatically to type bit varying
  HINT:  Specify a USING expression to perform the conversion.
   'ALTER TABLE views ALTER COLUMN cols TYPE BIT VARYING' {}
  </code></pre>
  <p>How can I change my script with the USING expression?</p>