Biplov
Biplov

Reputation: 1142

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')

Upvotes: 3

Views: 3588

Answers (1)

davidism
davidism

Reputation: 127200

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

Card.__table__.drop(db.engine)

Upvotes: 7

Related Questions