{
  "id": "python/pytest-django-database-access-not-allowed",
  "signature": "Failed: Database access not allowed, use the \"django_db\" mark or the \"db\" or \"transactional_db\" fixtures to enable it.",
  "signature_zh": "Failed：不允许访问数据库，请使用 \"django_db\" 标记或 \"db\"/\"transactional_db\" fixture 来启用。",
  "regex": "Failed:\\ 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 and isolated. Any ORM call in a test without @pytest.mark.django_db or the db fixture raises this failure.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-django 默认阻止数据库访问，以保持测试快速且隔离。任何没有 @pytest.mark.django_db 或 db fixture 的 ORM 调用都会引发此失败。",
  "versions": [
    {
      "version": "4.8",
      "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's plugin, not by the database backend; the failure occurs before any connection is attempted.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "NameError: name 'pytest' is not defined, or the mark is silently ignored if imported incorrectly.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "import pytest\n\n@pytest.mark.django_db\ndef test_create_user():\n    User.objects.create(email='a@b.com')\n    assert User.objects.count() == 1",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.96,
      "how": "def test_create_user(db):\n    User.objects.create(email='a@b.com')\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}