{
  "id": "python/pytest-django-db-access-error",
  "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' 夹具来启用。",
  "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 database access by default in tests to prevent accidental queries. The test attempts to query the database without the required marker or fixture.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-django 默认在测试中阻止数据库访问，以防止意外查询。测试在未使用所需标记或夹具的情况下尝试查询数据库。",
  "versions": [
    {
      "version": "4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This flag only skips migrations, it does not disable the database access blocker. The RuntimeError persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This enables database access for all tests, slowing down the suite and hiding tests that should not hit the database.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "import pytest\n\n@pytest.mark.django_db\ndef test_user_creation():\n    User.objects.create(username='test')\n    assert User.objects.count() == 1",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "def test_user_creation(db):\n    User.objects.create(username='test')\n    assert User.objects.count() == 1",
      "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.91,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}