Thomas Thomas - 1 year ago 88
Python Question

Rows are still present after calling delete() in SQLAlchemy

I want to have a Flask route that deletes all instances of a SQLAlchemy model,

. I call
, then redirect back to the page, but the old entries are still present. There was no error. Why weren't they deleted?

def log():
final_list = VisitLog.query.all()
return render_template('log.html', loging=final_list)

def logclear():
return redirect("log.html", code=302)

<a href="{{ url_for('logclear') }}">Clear database</a>

Answer Source

Just like other write operations, you must commit the session after executing a bulk delete.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download