How do you get SQLAlchemy to override MySQL "on update CURRENT_TIMESTAMP"

Posted by nocola on Stack Overflow See other posts from Stack Overflow or by nocola
Published on 2010-03-15T21:22:41Z Indexed on 2010/03/16 13:56 UTC
Read the original article Hit count: 187

Filed under:
|
|

I've inherited an older database that was setup with a "on update CURRENT_TIMESTAMP" put on a field that should only describe an item's creation. With PHP I have been using "timestamp=timestamp" on UPDATE clauses, but in SQLAlchemy I can't seem to force the system to use the set timestamp.

Do I have no choice and need to update the MySQL table (millions of rows)?

foo = session.query(f).get(int(1))
ts = foo.timestamp
setattr(foo, 'timestamp', ts)
setattr(foo, 'bar', bar)
www_model.www_Session.commit()

I have also tried:

foo = session.query(f).get(int(1))
setattr(foo, 'timestamp', foo.timestamp)
setattr(foo, 'bar', bar)
www_model.www_Session.commit()

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy