{
  "id": "python/pytest-django-db-access-not-allowed",
  "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\" fixture 以启用。",
  "regex": "RuntimeError:\\ Database\\ access\\ not\\ allowed,\\ use\\ the\\ \"django_db\"\\ mark,\\ or\\ the\\ \"db\"\\ or\\ \"transactional_db\"\\ fixtures\\ to\\ enable\\ it\\.",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "pytest-django blocks DB access by default to keep tests fast. Any ORM query in a test without the django_db marker or db fixture raises this error.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-django 默认阻止数据库访问以保持测试快速。任何未带 django_db 标记或 db fixture 的 ORM 查询都会引发此错误。",
  "versions": [
    {
      "version": "4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "That variable is for async ORM access, not for pytest-django's DB access guard.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Django is already set up; the guard is enforced by pytest-django at the connection level.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "import pytest\n\n@pytest.mark.django_db\ndef test_user_count():\n    from myapp.models import User\n    assert User.objects.count() == 0",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_user_count(db):\n    from myapp.models import User\n    assert User.objects.count() == 0",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}