Learn

Sometimes you will need to update a certain column value of an entry in your database. This is rather easy in the context of SQLAlchemy ORM and is done in the same way you would change Python object’s attribute.

The commands below change the email of a reader with id=3 and commit the changes to the database:

reader = Reader.query.get(3) reader.email = “[email protected]” db.session.commit()

If you want to undo the update, you can use

db.session.rollback()

instead of committing.

Instructions

1.

Using the get method, fetch a book entry with id = 19 and assign it to the variable called book_19.

2.

Change the month attribute of book_19 to June.

3.

Commit the change.

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?