{
  "id": "python/flask-circular-import",
  "signature": "ImportError: cannot import name 'db' from partially initialized module 'app' (most likely due to a circular import)",
  "signature_zh": "ImportError: 无法从部分初始化的模块 'app' 中导入 'db'（很可能是由于循环导入）",
  "regex": "ImportError:\\ cannot\\ import\\ name\\ 'db'\\ from\\ partially\\ initialized\\ module\\ 'app'\\ \\(most\\ likely\\ due\\ to\\ a\\ circular\\ import\\)",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Two modules import each other at module load time, typically models importing app and app importing models.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个模块在加载时互相导入，通常是 models 导入 app 而 app 又导入 models。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Only changes which side fails first; cycle remains.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Leaves db undefined and crashes later.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "def create_app():\n    app = Flask(__name__)\n    db.init_app(app)\n    return app",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.91,
      "how": "# extensions.py\nfrom flask_sqlalchemy import SQLAlchemy\ndb = SQLAlchemy()",
      "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-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}