Search code examples
pythonherokuflaskflask-sqlalchemyheroku-postgres

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?


Solution

  • 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/