0

I'm using fastapi with sqlalchemy, This is my code for inserting new record

def insert_price(db: Session, price_list: schemas.PriceList):
    db_price = models.PriceList(**price_list.dict())
    db.add(db_price)
    db.commit()
    db.refresh(db_price)
    return db_price

i have a unique column and i want to update on duplicate how can i handle that?

رضا پریور
  • 556
  • 1
  • 6
  • 16
  • 1
    Have you seen https://stackoverflow.com/questions/6611563/sqlalchemy-on-duplicate-key-update ? (in particular the newer answers shed some light on recent changes) – MatsLindh Jun 21 '23 at 09:59

0 Answers0