Skip to content Skip to sidebar Skip to footer

Sqlalchemy Update Not Working With Sqlite

I followed the (two) examples in this question: SQLAlchemy: a better way for update with declarative? And I'm finding that a model update does not happen when using sqlite with fla

Solution 1:

So I tried several different things. Here's what didn't work, and what finally did work:

Didn't work:

# this will throw an exception, "AttributeError: 'Task' object has no attribute 'update'"
db.session.query(Task).get(id).update({"state":state})
db.session.commit()

# this was the example in the linked SO thread:# does nothing
db.session.query(Task).filter_by(id=id).update({"state":state})

#this also does nothing
task = Task.query.filter_by(id=id)
task.state = state
db.session.commit()

#not this either
task = Task.query.get(id)
task.state = state
db.session.commit()

Did work:

#ok this works:
db.session.query(Task).filter_by(id=id).update({"state":state})
db.session.commit()

#and also this:
task = db.session.query(Task).get(id)
task.state = state
db.session.commit()

Post a Comment for "Sqlalchemy Update Not Working With Sqlite"