Dilli Dilli - 6 months ago 50
Python Question

Dropping Flask-SQLAlchemy table raises AttributeError

I'm trying to drop a table on my database, but I get the following error:

AttributeError: 'SQLAlchemy' object has no attribute '_run_visitor'


How do I drop a Flask-SQLAlchemy model's table?

db = SQLAlchemy(app)

class DeleteTable(Resource):
def get(self):
CardsDB.__table__.drop(db)

class CardsDB(db.Model):
__tablename__ = 'Cards'
id = db.Column(db.Integer, primary_key=True)
viewID = db.Column(db.Integer, db.ForeignKey('Views.id'))

api.add_resource(DeleteTable,'/user/delete/table')

Answer

drop takes an engine, not a Flask-SQLAlchemy extension object.

Card.__table__.drop(db.engine)