使用 Flask 升级 sqlalchemy 模式数据库[重复]

问题描述 投票:0回答:1

让我的应用程序在生产环境中使用 sqlalchemy 运行,但在新的更新中,我必须更新数据库架构以在表中添加新行。如果我重新启动网络服务器,我会收到一条错误消息,指出不存在这样的列。 如何更新数据库架构而不丢失生产中的任何数据?

我的跑步.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)

在 init_db.py 中我有这个:

def init_db(app):
    with app.app_context():
        db.create_all()
python flask sqlalchemy
1个回答
0
投票

这称为“迁移”数据库。 Flask-SQLAlchemy 有一个库来处理这个问题,称为 Flask-Alembic

© www.soinside.com 2019 - 2024. All rights reserved.