0

Have my app running in production with sqlalchemy but in my new update I had to update the database schema to add a new row in a table. If I restart my web server I get an error message saying that there is not such a column. How do I update the database schema without losing any data in production?

My run.py:

from myApp import create_app
from myApp.db_init import init_db


app = create_app()
init_db(app)

if __name__ == '__main__':
    app.run(debug=True)

In init_db.py I have this:

def init_db(app):
    with app.app_context():
        db.create_all()
flacoding
  • 145
  • 1
  • 12

1 Answers1

0

This is called migrating a database. Flask-SQLAlchemy has a library to handle this called Flask-Alembic.

noslenkwah
  • 1,702
  • 1
  • 17
  • 26
  • Ok. That's good. I have added this library to my project: alembic.revision('made changes') alembic.upgrade() and now I'm getting this error: raise util.CommandError("Target database is not up to date.") – flacoding May 12 '22 at 18:37