{
  "id": "python/django-model-foreignkey-validation",
  "signature": "django.core.exceptions.ValidationError: {'model': [ValidationError(['“test” is not a valid UUID.'])]}",
  "signature_zh": "验证错误：模型字段“test”不是有效的 UUID",
  "regex": "django\\.core\\.exceptions\\.ValidationError:\\ \\{'model':\\ \\[ValidationError\\(\\['“test”\\ is\\ not\\ a\\ valid\\ UUID\\.'\\]\\)\\]\\}",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "外键字段赋值了非 UUID 格式的字符串，但模型期望 UUID 类型",
  "root_cause_type": "generic",
  "root_cause_zh": "外键字段期望 UUID 类型，但传入了无效的字符串值",
  "versions": [
    {
      "version": "3.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "忽略验证直接保存",
      "why_fails": "Django 在保存前会进行字段验证，无法绕过",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "将字段类型改为 CharField",
      "why_fails": "改变模型结构需要迁移，且可能破坏外键关系",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "传入有效的 UUID 字符串",
      "success_rate": 1.0,
      "how": "import uuid; model_instance.foreign_key = uuid.UUID('550e8400-e29b-41d4-a716-446655440000')",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 UUID 对象而不是字符串",
      "success_rate": 0.95,
      "how": "from uuid import UUID; model_instance.foreign_key = UUID('550e8400-e29b-41d4-a716-446655440000')",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}