{
  "id": "python/flask-db-not-initialized",
  "signature": "RuntimeError: The current Flask app is not registered with this 'SQLAlchemy' instance. Did you forget to call 'init_app'?",
  "signature_zh": "RuntimeError: 当前 Flask 应用未注册到此 'SQLAlchemy' 实例。是否忘记调用 'init_app'？",
  "regex": "RuntimeError:\\ The\\ current\\ Flask\\ app\\ is\\ not\\ registered\\ with\\ this\\ 'SQLAlchemy'\\ instance\\.\\ Did\\ you\\ forget\\ to\\ call\\ 'init_app'\\?",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Using db.session outside an app context, or the SQLAlchemy extension was never bound to the app via db.init_app(app).",
  "root_cause_type": "generic",
  "root_cause_zh": "在应用上下文之外使用 db.session，或 SQLAlchemy 扩展从未通过 db.init_app(app) 绑定到应用。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "No app context; raises the same error.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Still requires init_app with the app instance.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "In factory: db.init_app(app); with app.app_context(): db.create_all()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Wrap script code: with app.app_context(): db.session.add(obj); db.session.commit()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-16",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}