Sqlmodel 0.0.14 throws strange Pydantic error for relationships when adding another field #723
Unanswered
junoriosity
asked this question in
Questions
Replies: 1 comment 1 reply
-
If you want to inherit from a model, starts with a Base that shares common attributes. from typing import List, Optional
from sqlmodel import Field, Relationship, SQLModel
class HeroBase(SQLModel):
name: str
secret_name: str
age: Optional[int] = None
class Hero(HeroBase, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
teams: List[Team] = Relationship(back_populates="heroes")
class HeroRead(HeroBase):
id: int
is_new: bool = False Only the ones with table==True are created. You should put is_new inside Hero, otherwise, this attribute isn't in the database. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
This is the result we get
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.14
Python Version
3.12
Additional Context
We use Pydantic version 2.5.2
Beta Was this translation helpful? Give feedback.
All reactions