Example of using Alembic with the SQLModel ORM.
If this content has helped you, please consider making a donation. Your support makes a real difference and helps the project grow! 💙
Crafted with 💙 by Renato Cruz. Got questions or feedback? Reach out anytime!
What I'm listening to while I code or study 😎🎵:
Your donation keeps this project alive and helps me continue creating and sharing useful content.
https://github.com/sponsors/natorsc/
b1839493-2afe-484d-9272-82a3e402b36f
To fix the error:
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=30), nullable=False),
^^^^^^^^
NameError: name 'sqlmodel' is not defined.Import the sqlmodel into the script.py.mako file.
Example:
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# To fix the error:
# sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=30), nullable=False),
# ^^^^^^^^
# NameError: name 'sqlmodel' is not defined.
import sqlmodel
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}