{
  "id": "python/pytest-django-fixture-db-access",
  "signature": "RuntimeError: Database access not allowed, use the \"django_db\" mark or the \"db\" or \"transactional_db\" fixtures to enable it.",
  "signature_zh": "RuntimeError: 不允许访问数据库，请使用 \"django_db\" 标记或 \"db\" 或 \"transactional_db\" fixtures 来启用它。",
  "regex": "RuntimeError:\\ Database\\ access\\ not\\ allowed,\\ use\\ the\\ \"django_db\"\\ mark\\ or\\ the\\ \"db\"\\ or\\ \"transactional_db\"\\ fixtures\\ to\\ enable\\ it\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "pytest-django blocks database access by default. The test tries to query the database without the django_db mark or db fixture.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-django 默认阻止数据库访问。测试尝试查询数据库但没有使用 django_db 标记或 db fixture。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The block is enforced by pytest-django, not Django settings.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Breaks Django test integration and may cause other failures.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "pytest-django still applies the block unless marked.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "@pytest.mark.django_db\ndef test_create_user():\n    User.objects.create(username='test')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_create_user(db):\n    User.objects.create(username='test')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.mark.django_db(transaction=True)\ndef test_transaction():\n    ...",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}