执行db.create_all()创建表时出错,问题已经解决

执行db.create_all()创建表时出错

直接上干货

Flask-SQLALchemy=3.0.3 # 似乎3.0版本以上都会出现这种错误,而不关SQLALchemy的事
SQLALchemy=2.0.5

  1. 引发错误如下:Flask-SQLALchemy似乎3.0版本以上都会出现这种错误

    RuntimeError: Working outside of application context.

    This typically means that you attempted to use functionality that needed
    the current application. To solve this, set up an application context
    with app.app_context(). See the documentation for more information.`

  2. SQLALchemy2.0版本以上似乎都会出现这种错误

    AttributeError: module 'sqlalchemy' has no attribute 'all'

版本为以下组合可以
Flask-SQLALchemy(3.0以下版本)和 SQLALchemy(2.0以下版本) 组合可用
例如:
Flask-SQLALchemy=2.5.1
SQLALchemy=1.4.46

posted @ 2023-03-13 17:37  晴天看恒星  阅读(484)  评论(0编辑  收藏  举报