0

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?

2

1 Answer 1

1

You can use drop()

from sqlalchemy import create_engine
engine = create_engine("...")
my_table.__table__.drop(engine)
Sign up to request clarification or add additional context in comments.

2 Comments

This is really the right answer. Will SqlAlchemy recreate the table in its new form next time it runs?
No.. you might need to look into migrations for that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.