错误为'No application found. Either work inside a view function or push'
RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
我的create_app()是:
app = Flask(__name__, static_folder='static')
app.config.from_object(Config)
db.init_app(app)
Migrate().init_app(app, db)
with app.app_context():
from slackbot.v1 import bp as v1_bp
app.register_blueprint(v1_bp)
from models import SlackerModel,UrlModel,ParaModel
db.create_all()
return app
当它运行create_app()时,它会给我错误。
但是,当我替换db.create_all()
的行时
@manager.command
def create_db():
db.create_all()
它不起作用!
答案 0 :(得分:0)
我找到原因!在模型中。我导入了db' db'来自myapp的init.py,但它应该从我的数据库中导入。