# RuntimeError: Database access not allowed, use the 'django_db' mark or the 'db' or 'transactional_db' fixtures to enable it.

- **ID:** `python/pytest-django-db-access-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   import pytest

@pytest.mark.django_db
def test_user_creation():
    User.objects.create(username='test')
    assert User.objects.count() == 1
   ```
2. **** (93% success)
   ```
   def test_user_creation(db):
    User.objects.create(username='test')
    assert User.objects.count() == 1
   ```

## Dead Ends

- **** — This flag only skips migrations, it does not disable the database access blocker. The RuntimeError persists. (90% fail)
- **** — This enables database access for all tests, slowing down the suite and hiding tests that should not hit the database. (65% fail)
