{"id":"0e31e57deaf79843","repo":"sqlalchemy/alembic","slug":"walked-too-far","errorCode":null,"errorMessage":"Walked too far","messagePattern":"Walked too far","errorType":"exception","errorClass":"RevisionError","httpStatus":null,"severity":"error","filePath":"alembic/script/revision.py","lineNumber":1128,"sourceCode":"        if match:\n            branch_label, symbol, relative = match.groups()\n            rel_int = int(relative)\n            if rel_int >= 0:\n                if symbol is None:\n                    # Downgrading to current + n is not valid.\n                    raise RevisionError(\n                        \"Relative revision %s didn't \"\n                        \"produce %d migrations\" % (relative, abs(rel_int))\n                    )\n                # Find target revision relative to given symbol.\n                rev = self._walk(\n                    symbol,\n                    rel_int,\n                    branch_label,\n                    no_overwalk=assert_relative_length,\n                )\n                if rev is None:\n                    raise RevisionError(\"Walked too far\")\n                return branch_label, rev\n            else:\n                relative_revision = symbol is None\n                if relative_revision:\n                    # Find target revision relative to current state.\n                    if branch_label:\n                        cr_tuple = util.to_tuple(current_revisions)\n                        symbol_list: Sequence[str]\n                        symbol_list = self.filter_for_lineage(\n                            cr_tuple, branch_label\n                        )\n                        if not symbol_list:\n                            # check the case where there are multiple branches\n                            # but there is currently a single heads, since all\n                            # other branch heads are dependent of the current\n                            # single heads.\n                            all_current = cast(\n                                set[Revision], self._get_all_current(cr_tuple)","sourceCodeStart":1110,"sourceCodeEnd":1146,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/script/revision.py#L1110-L1146","documentation":"Raised by _parse_downgrade_target when a relative downgrade with an explicit symbol ('symbol+n') walked past the end of the line and produced no revision. The requested number of forward steps from that symbol exceeds available migrations. It is a RevisionError.","triggerScenarios":"Issuing something like 'alembic downgrade <revid>+5' where fewer than 5 forward migrations exist from revid; walking past head while assert_relative_length is on.","commonSituations":"Overestimating how many migrations exist above a given revision; stale assumptions after migrations were removed.","solutions":["Reduce the step count or use the symbolic 'head' as the target.","Verify available migrations above the symbol with 'alembic history'.","Pass the explicit destination revision id."],"exampleFix":"# before\nalembic downgrade deadbeef+10   # fewer than 10 above\n# after\nalembic downgrade deadbeef+2    # or 'alembic downgrade head'","handlingStrategy":"validation","validationCode":"# count available migrations above the symbol\nrev = script.get_revision(symbol)\nabove = list(script._revision_map._get_descendant_nodes([rev]))\nif int(steps) > len(above):\n    raise ValueError('only %d migrations above %s' % (len(above), symbol))","typeGuard":null,"tryCatchPattern":"from alembic.script.revision import RevisionError\ntry:\n    command.downgrade(cfg, '%s+%s' % (symbol, steps))\nexcept RevisionError as e:\n    if 'Walked too far' in str(e):\n        command.downgrade(cfg, 'head')  # cap at head","preventionTips":["Verify available migrations above a symbol before stepping.","Cap forward downgrades at 'head' instead of fixed counts.","Use absolute targets in automation."],"tags":["relative-revision","downgrade","walk","alembic"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}