{
  "id": "python/django-foreign-key-delete-protection",
  "signature": "django.db.models.deletion.ProtectedError: Cannot delete some instances of model 'Author' because they are referenced through protected foreign keys: 'Book.author'",
  "signature_zh": "删除保护错误：无法删除 'Author' 模型的某些实例，因为它们通过受保护的外键 'Book.author' 被引用",
  "regex": "django\\.db\\.models\\.deletion\\.ProtectedError:\\ Cannot\\ delete\\ some\\ instances\\ of\\ model\\ 'Author'\\ because\\ they\\ are\\ referenced\\ through\\ protected\\ foreign\\ keys:\\ 'Book\\.author'",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Deleting a parent object that has child objects with on_delete=PROTECT.",
  "root_cause_type": "generic",
  "root_cause_zh": "删除具有 on_delete=PROTECT 子对象的父对象。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Changing on_delete to CASCADE in model requires migration and may delete data unintentionally.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using raw SQL DELETE ignores Django's protection and can cause orphaned records.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Delete child objects first: Book.objects.filter(author=author).delete() then author.delete()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Change on_delete=models.CASCADE in model and run migrations to allow cascading delete.",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}