I’m using SQLModel with Alembic for database migrations in my project. However, Alembic doesn’t seem to recognize my models and creates empty migrations.
Here’s the code for my model:
from sqlmodel import Field, SQLModel
from app.model.base_model import BaseModel
class UserType(Enum):
buyer = "buyer"
seller = "seller"
class User(BaseModel):
user_id: int = Field(default=None, primary_key=True, index=True)
role: UserType = Field(default="buyer")
name: str = Field(default=None)
email: str = Field(default=None)
description: str = Field(default=None)
password_hash: str = Field(default=None)
profile_picture: str = Field(default=None)
In my env.py file, I’m importing the models like this:
from app import model # noqa
(import from init.py)
And I’ve set the target_metadata to SQLModel.metadata:
target_metadata = SQLModel.metadata
Despite this, when I run alembic revision –autogenerate, it creates an empty migration file with upgrade() and downgrade() functions that just contain pass.
I’ve followed the documentation closely, but I can’t figure out why Alembic isn’t recognizing my models. Any help would be greatly appreciated.
DARK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.