i try to delete some record from my sql but getting this error sqlalchemy.exc.InvalidRequestError: Object '<Barname at 0x21395231280>' is already attached to session '2' (this is '3') this is my delete func:
@views.route("/delete/<int:id>")
def delete(id):
bars = Barname.query.get_or_404(id)
if bars :
db.session.delete(bars)
db.session.commit()
flash("delete successfully" , category="success")
return redirect("/home.html")
and this is part of my model :
class Barname(db.Model):
__tablename__ = "barnamees"
id = db.Column(db.Integer, primary_key=True)
data = db.Column(db.String(10000))
date = db.Column(db.String(10000))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
i really stuck here for too long and can't find the answer also i'm really new to coding so sorry if my code and question look dumb