1

In the below example given here: https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/

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

How can create the schema which uses only name and age and ignores the other variables/rows ?

Akash Ranjan
  • 922
  • 12
  • 24

2 Answers2

1

Does making secret_name Optional solves your problem?

class Hero(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)
    name: str
    secret_name: Optional[str]
    age: Optional[int] = None

hero = Hero(name="some name", age=99) 

Should work fine and you don't have to pass secret_name param

0

As suggested in another answer, using a non-optional value in the SQLModel definition implies that column cannot be Nullable (SQL for None).