python
config_error
ai_generated
true
RuntimeError: The current Flask app is not registered with this 'SQLAlchemy' instance.
ID: python/flask-sqlalchemy-no-application-found
80%Fix Rate
86%Confidence
0Evidence
2024-06-06First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
db = SQLAlchemy() was created in a module but db.init_app(app) was never called, or a different app instance is active.
generic中文
在模块中创建了 db = SQLAlchemy(),但从未调用 db.init_app(app),或当前激活的是另一个 app 实例。
Workarounds
-
95% success
db = SQLAlchemy() def create_app(): app = Flask(__name__) db.init_app(app) return app -
90% success
app = create_app() with app.app_context(): db.create_all()
Dead Ends
Common approaches that don't work:
-
90% fail
Instance still lacks the app binding.
-
85% fail
Creates two instances; models attach to the wrong one.