How can I delete a record using its id?
I currently have the following code:
@app.route('/delete/<cid>')
def dele(cid):
# o= catagory.query.get(cid)
a=db.session.query(catagory).filter(bool(cid)).delete(synchronize_session='fetch')
db.session.commit()
return "deleted"
But it will delete the entire data in that table. I only want to delete a specific record by specifying its id
I also use this code to implement that :
@app.route('/delete/<cid>')
def dele(cid):
k=catagory.query.get()
e = catagory.query.filter_by(cid='"+cid+"').first()
print (cid)
a = db.session.delete(e)
db.session.commit()
return "deleted"
My table name is catagory
and cid
is the column in catagory
table