I'm using alembic migrations for a flask+sqlalchemy project and things work as expected till I try to query the models in alembic.

from models import StoredFile

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('stored_file', sa.Column('mimetype', sa.Unicode(length=32))
    for sf in StoredFile.query.all():
        sf.mimetype = guess_type(sf.title)

The above code gets stuck after adding column and never comes out. I guess the StoredFile.query is trying to use a different database connection than the one being used by alembic. (But why? Am I missing something in env.py?)

I could solve it by using the op.get_bind().execute(...) but the question is how can I use the models directly in alembic?

Edit
Report