mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-08-15 10:11:34 +08:00
✨ Add support for Pydantic v2 (while keeping support for v1 if v2 is not available), including initial work by AntonDeMeester (#722)
Co-authored-by: Mohamed Farahat <farahats9@yahoo.com> Co-authored-by: Stefan Borer <stefan.borer@gmail.com> Co-authored-by: Peter Landry <peter.landry@gmail.com> Co-authored-by: Anton De Meester <antondemeester+github@gmail.com>
This commit is contained in:

committed by
GitHub

parent
5b733b348d
commit
fa2f178b8a
@ -46,7 +46,7 @@ def on_startup():
|
||||
@app.post("/heroes/", response_model=HeroRead)
|
||||
def create_hero(hero: HeroCreate):
|
||||
with Session(engine) as session:
|
||||
db_hero = Hero.from_orm(hero)
|
||||
db_hero = Hero.model_validate(hero)
|
||||
session.add(db_hero)
|
||||
session.commit()
|
||||
session.refresh(db_hero)
|
||||
|
Reference in New Issue
Block a user