Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a Postgres schema with flask-sqlalchemy?

I'm running a simple Flask app with Heroku, and I can run the following command to create all the tables:

db.create_all()

However, I ship new stuff frequently and I often need to add new columns to existing tables. Is there an easy way to do this?

If I need to manually create a new column with Postgres, how would I access the repl for Heroku's Postgres database?

like image 722
Abs Avatar asked May 31 '26 18:05

Abs


1 Answers

You should be using migrations.

This is a great plugin for that: https://flask-migrate.readthedocs.io/en/latest/

and this is a good explanation about how to get going with that: https://realpython.com/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/

like image 62
Daniel da Rocha Avatar answered Jun 02 '26 09:06

Daniel da Rocha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!