{"record":{"id":"27f05c6a3c7794b5","repo":"BerriAI/litellm","slug":"database-migration-failed-after-4-attempts-retry","errorCode":null,"errorMessage":"Database migration failed after 4 attempts (retry loop exhausted by timeouts or repeated idempotent-recovery continues). Check database connectivity, load, and _prisma_migrations ledger state.","messagePattern":"Database migration failed after 4 attempts \\(retry loop exhausted by timeouts or repeated idempotent-recovery continues\\)\\. Check database connectivity, load, and _prisma_migrations ledger state\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"litellm-proxy-extras/litellm_proxy_extras/utils.py","lineNumber":678,"sourceCode":"                                raise RuntimeError(\n                                    f\"Failed to mark migration {name} as applied \"\n                                    f\"after idempotent recovery. Manual \"\n                                    f\"intervention may be required.\\n\\n\"\n                                    f\"Detail: {resolve_err}\"\n                                ) from resolve_err\n                            continue\n\n                        raise RuntimeError(\n                            \"Database migration failed and cannot be auto-recovered. \"\n                            f\"Manual intervention required.\\n\\nPrisma error:\\n{stderr}\"\n                        ) from e\n\n                    raise RuntimeError(\n                        \"Database migration failed and cannot be auto-recovered. \"\n                        f\"Manual intervention required.\\n\\nPrisma error:\\n{stderr}\"\n                    ) from e\n\n            raise RuntimeError(\n                \"Database migration failed after 4 attempts (retry loop \"\n                \"exhausted by timeouts or repeated idempotent-recovery \"\n                \"continues). Check database connectivity, load, and \"\n                \"_prisma_migrations ledger state.\"\n            )\n        finally:\n            os.chdir(original_dir)\n\n    @staticmethod\n    def apply_replica_identity_full_if_requested() -> bool:\n        \"\"\"\n        Re-assert REPLICA IDENTITY FULL on LiteLLM's tables when the operator\n        opted in via LITELLM_SET_REPLICA_IDENTITY_FULL.\n\n        Prisma leaves new tables at the Postgres default, which logical\n        replication consumers reject, so the setting has to be re-applied after\n        every migration run rather than once by hand.\n","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm-proxy-extras/litellm_proxy_extras/utils.py#L660-L696","documentation":"Error \"Database migration failed after 4 attempts (retry loop exhausted by timeouts or repeated idempotent-recovery continues). Check database connectivity, load, and _prisma_migrations ledger state.\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm-proxy-extras/litellm_proxy_extras/utils.py:678 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database connectivity and load; inspect the _prisma_migrations table for failed entries and resolve them with prisma migrate resolve before retrying."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}