'Upgrading sqlalchemy schema database using Flask [duplicate]

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()


Solution 1:[1]

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

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 noslenkwah