'How to delete or modify a database table using Flask-SQLAlchemy?

Is there a way to delete or modify a table using flask-sqlalchemy?

I am working on a Flask-based web app. I switched to flask-sqlalchemy as my project is on Heroku and I had to connect my table to Heroku PostgreSQL. I made a flask-sqlalchemy table and created it using the db.create_all() command.

Now, for my app to fulfill its purpose, it is of utmost importance to save images, the best way of which I found to be to add them to the database.

Now, I want to change the particular table class to store a column called image as image = db.Column(db.Text, nullable=False) but I cannot. The former schema is unchanged and it gives me an error signifying that the column image does not exist every time I try to access or add something to the table.

How to do this?



Solution 1:[1]

You can use drop()

from sqlalchemy import create_engine
engine = create_engine("...")
my_table.__table__.drop(engine)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ammar Aslam