Reputation: 183
I'm using FastAPI with SQLModel which is based on pydantic, SQLAlchemy and type hints. And I'm trying to create a BitInteger
(int64
is enough) column. How do I do that?
My sql model declaration looks like that
class ItemBase(sqlmodel.SQLModel):
name: str
price: int
class Item(ItemBase, table=True):
id: int = sqlmodel.Field(default=None, primary_key=True)
class ItemCreate(ItemBase):
pass
Thanks in advance!
Upvotes: 4
Views: 5302
Reputation: 52802
From the issue documenting how to make BigIntegers work with SQLModel:
id: int = Field(default_factory=next_val, sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
You might need to adjust it slightly for your usage, but using a specific sqlalchemy column type seems to be the way.
Upvotes: 8