Search code examples
sqlalchemy

SQLAlchemy simply doesn't update a row and it makes me crazy


I hope you are all ok!!! . Working on Sunday :O!!

I have the next DB named 'books' and a table named equally with the following structure:

id
title
author
pages
published

Data Base with columns

I am using SQLALCHEMY to update the title of row id==1, but it doesn't work. There is not errors just it executes normally.

engine = create_engine(config.DATABASE_URI)
Session = sessionmaker(bind=engine)
s= Session()

tabla_libros=meta.tables['books']
stmt= update(tabla_libros).values({'title':'futurehead'}).where(tabla_libros.c.id==1)
engine.execute(stmt)
s.commit()

It doesn't update the value on BD nor shows an error.

I appreciate some help thanks!!


Solution

  • I solved my question !!, As @snakecharmerb said as comment. The error is related to use session() AND engine.execute. The changes that I did with engine.execute() was reverted with session() because I did nothing with the last.

    Thanks to all !! have a good day