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.
```python
from flask import Flask from flask_sqlalchemy import SQLAlchemy import os app = Flask(__name__) class BaseConfig(): DEBUG = True # 获取项目目录 APP_PATH = os.path.dirname(__file__) # # sqlite数据库url SQLALCHEMY_DATABASE_URI = f'sqlite:///{APP_PATH}/database' SQLALCHEMY_TRACK_MODIFICATIONS = True # 跟踪数据库修改 SQLALCHEMY_ECHO = True # 对调试很有用 app.config.from_object(BaseConfig) db = SQLAlchemy(app) class User(db.Model): # 模型类继承db.Model uid = db.Column(db.INTEGER, primary_key=True) username = db.Column(db.String(50)) password = db.Column(db.String(40), index=True) with app.app_context(): db.drop_all() db.create_all() # 创建所有表
```
with app.app_context():
db.drop_all() db.create_all() # 创建所有表