{"record":{"id":"a09bd9daac43f15e","repo":"BerriAI/litellm","slug":"database-not-connected-please-connect-a-database","errorCode":null,"errorMessage":"Database not connected. Please connect a database.","messagePattern":"Database not connected\\. Please connect a database\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/cache_settings_endpoints.py","lineNumber":595,"sourceCode":"        description=\"The litellm-changed-by header enables tracking of actions performed by authorized users on behalf of other users, providing an audit trail for accountability\",\n    ),\n):\n    \"\"\"\n    Save cache settings to database and initialize cache.\n\n    This endpoint:\n    1. Encrypts sensitive fields (passwords, etc.)\n    2. Saves to LiteLLM_CacheConfig table\n    3. Reinitializes cache with new settings\n    \"\"\"\n    from litellm.proxy.proxy_server import (\n        prisma_client,\n        proxy_config,\n        store_model_in_db,\n    )\n\n    if prisma_client is None:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": \"Database not connected. Please connect a database.\"},\n        )\n\n    if store_model_in_db is not True:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": \"Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature.\"},\n        )\n\n    try:\n        # Read the stored row first: its decrypted values back any credential the\n        # caller echoed back redacted, and its key set drives the audit diff.\n        existing_row: Final = await _cache_config_table(prisma_client).find_unique(where={\"id\": \"cache_config\"})\n        before_settings: dict[str, object] | None = None\n        saved_settings: dict[str, object] = {}\n        if existing_row is not None and existing_row.cache_settings:\n            before_settings = _parse_stored_settings(existing_row.cache_settings)","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cache_settings_endpoints.py#L577-L613","documentation":"POST /cache/settings persists new cache settings (encrypting sensitive fields) to LiteLLM_CacheConfig and reinitializes the cache. It hard-requires a database: if prisma_client is None it raises HTTP 500 'Database not connected. Please connect a database.' before touching anything. Unlike most management endpoints this check happens with a 500 status, because persisting settings is a server-side capability requirement, not a client request problem.","triggerScenarios":"POST /cache/settings with a settings payload against a proxy launched without DATABASE_URL; trying to configure Redis caching through the Admin UI on a config-only deployment.","commonSituations":"Attempting UI-driven cache configuration on a lightweight proxy without Postgres; DATABASE_URL not propagated to the container that hosts the settings endpoint; evaluating cache features before standing up the production database.","solutions":["Provision PostgreSQL and set DATABASE_URL=\"postgresql://...\", then restart the proxy","Verify with GET /cache/settings (which reads current values) that the DB-backed flow works end-to-end","Then re-POST the settings; note the companion requirement STORE_MODEL_IN_DB=True for this same endpoint (see the next error)"],"exampleFix":"# before: no DATABASE_URL\nlitellm --config config.yaml  # POST /cache/settings -> 500 Database not connected\n\n# after\nexport DATABASE_URL=\"postgresql://user:pass@db:5432/litellm\"\nlitellm --config config.yaml  # POST /cache/settings -> 200","handlingStrategy":"validation","validationCode":"import os\n\n# /cache/settings (POST) needs BOTH a DB and the store-model flag\nassert os.getenv(\"DATABASE_URL\", \"\").startswith(\"postgresql://\"), \"DB required\"\nassert os.getenv(\"STORE_MODEL_IN_DB\", \"\").lower() == \"true\", \"STORE_MODEL_IN_DB=True required\"","typeGuard":null,"tryCatchPattern":"import httpx\n\ntry:\n    r = httpx.post(f\"{PROXY_URL}/cache/settings\", json=settings, headers=hdrs)\n    r.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    detail = e.response.json().get(\"detail\", {})\n    if e.response.status_code == 500 and \"Database not connected\" in str(detail):\n        raise RuntimeError(\"set DATABASE_URL and restart the proxy\") from e\n    raise","preventionTips":["Provision Postgres before enabling UI-driven cache configuration","Include DATABASE_URL and STORE_MODEL_IN_DB in the same deployment checklist"],"tags":["litellm-proxy","database","postgres","cache","configuration"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T10:36:37.832Z"}