Skip to content
Discussion options

You must be logged in to vote

Just curious - why would you like to separate your Pydantic logic and SQLModel logic? Non-table SQLModel classes (i.e., without table=true) won't create tables and will effectively function as Pydantic models (more in the FastAPI and Pydantic Tutorial, in particular the Multiple Models tutorial).

Adapted to your example, this would look like the following:

from typing import Optional

from sqlmodel import Field, SQLModel

class MyType(SQLModel):
    some_attr: Optional[str] = Field(index=True)
    some_other_attr: int = None
    

class MyTypeSQL(MyType, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)

If using SQLite (for example), this code would create the fol…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants