Answer the question
In order to leave comments, you need to log in
How to delete multiple rows from a table?
Hello!
The table has several columns, one of them with a date like: 2020-09-27T17:00:00.000Z.
It is required to delete several rows with old data for previous days. I make a query like:
delete = DayData.query.filter(DayData.date.between('2020-09-27T16:00:00.000Z', '2020-09-28T11:00:00.000Z'))
db.session.delete(delete)
db.session.commit()
sqlalchemy.orm.exc.UnmappedInstanceError: Class 'flask_sqlalchemy.BaseQuery' is not mapped
Answer the question
In order to leave comments, you need to log in
I found a solution, it was necessary to skip through the cycle.
This code is working:
delete = DayData.query.filter(DayData.date.between('2020-09-27T16:00:00.000Z', '2020-09-28T11:00:00.000Z'))
for i in delete:
db.session.delete(i)
db.session.commit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question