2

I want to update a row of a table.

To add I used,

session.add(unit) #here unit is unit object of class unit
session.commit()

To update I tried,

session.merge(unit)
session.commit()

However, in the database there are other columns, e.g. create_by, created_on, updated_on, which are not set in the unit object, so these are set NULL upon the merge.

0

2 Answers 2

4

You can just modify properties of the class you use to represent the row and call session.commit(). For example:

# Add a new user
user = User(name="John", age=20)
session.add(user)
session.commit()

# Modify the user we just added
user.age = 21
session.commit()
Sign up to request clarification or add additional context in comments.

Comments

-1

I used merge(unit), by modifying model structure. Initialization of create_by, created_on, updated_on etc. removed from constructor init(...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.