2

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!

DarkSidds
  • 164
  • 11

1 Answers1

6

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84