from app import app, db from flask import g, current_app from flask_sqlalchemy import SQLAlchemy if __name__ == "__main__": def get_db(): if 'db' not in g: g.db = SQLAlchemy(current_app) return g.db get_db().create_all() #db.create_all()