{
  "id": "python/flask-sqlalchemy-multiple-instances",
  "signature": "RuntimeError: A 'SQLAlchemy' instance has already been registered on this Flask app. Import and use that instance instead.",
  "signature_zh": "RuntimeError: 此 Flask 应用上已注册了 'SQLAlchemy' 实例。请改为导入并使用该实例。",
  "regex": "RuntimeError:\\ A\\ 'SQLAlchemy'\\ instance\\ has\\ already\\ been\\ registered\\ on\\ this\\ Flask\\ app\\.\\ Import\\ and\\ use\\ that\\ instance\\ instead\\.",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Two db = SQLAlchemy() objects created in different modules and both init_app(app) called.",
  "root_cause_type": "generic",
  "root_cause_zh": "在不同模块中创建了两个 db = SQLAlchemy() 对象，并且都调用了 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": "Raises again; second instance is unusable.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Old versions silently misbehave; data bugs appear later.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Create db once in extensions.py: from flask_sqlalchemy import SQLAlchemy; db = SQLAlchemy()  # import everywhere else",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "In factory: from .extensions import db; db.init_app(app)  # only once",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}