{
  "id": "python/sqlalchemy-relationship-delete-orphan-without-cascade",
  "signature": "sqlalchemy.exc.FlushError: Instance <Child at 0x...> has a NULL identity key.  If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured correctly.",
  "signature_zh": "实例 <Child at 0x...> 具有 NULL 标识键。如果这是自动生成的值，请检查数据库表是否允许生成新的主键值，以及映射的 Column 对象配置是否正确。",
  "regex": "sqlalchemy\\.exc\\.FlushError:\\ Instance\\ <Child\\ at\\ 0x\\.\\.\\.>\\ has\\ a\\ NULL\\ identity\\ key\\.\\ \\ If\\ this\\ is\\ an\\ auto\\-generated\\ value,\\ check\\ that\\ the\\ database\\ table\\ allows\\ generation\\ of\\ new\\ primary\\ key\\ values,\\ and\\ that\\ the\\ mapped\\ Column\\ object\\ is\\ configured\\ correctly\\.",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Trying to delete a child object that is not properly associated or has missing primary key, often due to missing cascade delete-orphan.",
  "root_cause_type": "generic",
  "root_cause_zh": "试图删除未正确关联或缺少主键的子对象，通常由于缺少 cascade delete-orphan。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "May conflict with auto-increment; not scalable.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The child still exists in session and gets flushed.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "class Parent(Base):\n    children = relationship('Child', cascade='all, delete-orphan')\n# Then remove child: parent.children.remove(child)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "session.delete(child)\nsession.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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-01-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}