from sqlmodel import Field, SQLModel
class Hero(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
name: str
secret_name: str
age: Optional[int] = None
In the above the type annotation for id
is int
but in the Field
its mentioned that this column can have a default value of None
Then as per that it should be
id: int | None = Field(default=None, primary_key=True)
or
id: Optional[int] = Field(default=None, primary_key=True)
1