How to migrate data in sqlite alembic migration?
<p>I have a column <code>goods.visible</code> (boolean) and i want to replace it with <code>goods.status</code> (enum).</p>

<p>I need to replace one column with another and migrate data using sqlalchemy (to use its data type conversion mechanism). As sqlite does not support ALTER TABLE for this, I have to use <code>batch_alter_table</code> alembic operation for this.</p>

<p>My migration looks like the following. It throws <code>sqlite3.OperationalError: no such column: goods.status</code>, because in my old table there is no such column (new table is created for migration using batch)</p>

<pre><code>def upgrade():
    with op.batch_alter_table('goods') as batch_op:
        batch_op.add_column(sa.Column('status', sa.Enum('published', 'unpublished', 'deleted'), nullable=True))

        conn = op.get_bind()
        Session = sa.orm.sessionmaker()
        session = Session(bind=conn)
        for good in session.query(Good):
            # I want to perform some data updates &amp; insert data into new column
        batch_op.drop_column('visible')
</code></pre>

<p>If i will add <code>load_only</code> to specify columns to be selected from the table:
<code>sqlite3.OperationalError: no such column: goods.status</code></p>

<p>i will get error <code>sqlalchemy.exc.ArgumentError: Can't find property named 'visible' on the mapped entity Mapper|Good|goods in this Query.</code>. I understand why i get it - i have no more property visible in my model.</p>

<p>How i can migrate data using alembic in this case?</p>

<p>I tried to use raw queries.. but it says there is no table: </p>

<pre><code>    s = sa.sql.select([sa.sql.text('goods.*')])
    for row in conn.execute(s):
        print(row)
</code></pre>

<p>Hovewer inspector displays <code>goods</code> table:</p>

<pre><code> inspector = sa.inspect(conn.engine)
    for table_name in inspector.get_table_names():
        print(table_name)
        for column in inspector.get_columns(table_name):
            print("Column: %s" % column['name'])
</code></pre>

<p>Displays</p>

<pre><code>goods
Column: id
Column: name
Column: price
Column: visible
</code></pre>