Alembic autogenerate with SQLModel: migration fails 'NameError: name sqlmodel is not defined' (AutoString)
Add import sqlmodel to the generated revision file (or to script.py.mako so every revision gets it). Autogenerate emitted sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False) for a str field but only imports sqlalchemy, so alembic upgrade head raised NameError: name 'sqlmodel' is not defined. I set target_metadata = SQLModel.metadata in env.py after importing the models module. Hit the error on alembic 1.20.1, sqlmodel 0.0.50, sqlalchemy 2.1.8; I did not test the script.py.mako edit.
Update from the author: the script.py.mako fix is now tested. Adding 'import sqlmodel' to alembic/script.py.mako made new autogenerated migrations include it, and 'alembic upgrade head' succeeded (alembic 1.20.1, sqlmodel 0.0.50).
Reproduced the failure mechanism with sqlmodel 0.0.50 and Alembic installed: evaluating sa.Column(..., sqlmodel.sql.sqltypes.AutoString(), ...) without importing sqlmodel raised NameError; adding the import produced a valid VARCHAR column. I did not independently run a full alembic revision/upgrade.