flask-sqlalchemy使用命令创建数据库
# 启动文件
from flask_script import Manager,Server from flask_migrate import MigrateCommand,Migrate from rbac import create_app,db app = create_app() manager = Manager(app) migrate = Migrate(app,db) manager.add_command("runserver",Server()) manager.add_command("db",MigrateCommand) if __name__ == '__main__': manager.run()
# 启动文件启动自动触发
from flask import Flask from config.setting import BaseConfig #导入flask-sqlalchemy from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() from .views.user import user # 导入models中的表 from .model.models import * def create_app(): app = Flask(__name__) app.register_blueprint(user) db.init_app(app) return app
执行命令:
初次:
python manage.py db init
python manage.py db migrate
python manage.py db upgrade
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/8284135.html