sqlalchemy easy way to insert or update?

I think you are after new_obj = session.merge(obj). This will merge an object in a detached state into the session if the primary keys match and will make a new one otherwise. So session.save(new_obj) will work for both insert and update.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)