{"record":{"id":"69bc2c4aa7fa9f6f","repo":"golang-migrate/migrate","slug":"next-sequence-number-s-too-large-at-most-d-digi","errorCode":null,"errorMessage":"next sequence number %s too large, at most %d digits are allowed","messagePattern":"next sequence number (.+?) too large, at most (.+?) digits are allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/commands.go","lineNumber":53,"sourceCode":"\t\tif idx < 1 { // Using 1 instead of 0 since there should be at least 1 digit\n\t\t\treturn \"\", fmt.Errorf(\"malformed migration filename: %s\", filename)\n\t\t}\n\n\t\tvar err error\n\t\tmatchSeqStr = matchSeqStr[0:idx]\n\t\tnextSeq, err = strconv.ParseUint(matchSeqStr, 10, 64)\n\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tnextSeq++\n\t}\n\n\tversion := fmt.Sprintf(\"%0[2]*[1]d\", nextSeq, seqDigits)\n\n\tif len(version) > seqDigits {\n\t\treturn \"\", fmt.Errorf(\"next sequence number %s too large, at most %d digits are allowed\", version, seqDigits)\n\t}\n\n\treturn version, nil\n}\n\nfunc timeVersion(startTime time.Time, format string) (version string, err error) {\n\tswitch format {\n\tcase \"\":\n\t\terr = errInvalidTimeFormat\n\tcase \"unix\":\n\t\tversion = strconv.FormatInt(startTime.Unix(), 10)\n\tcase \"unixNano\":\n\t\tversion = strconv.FormatInt(startTime.UnixNano(), 10)\n\tdefault:\n\t\tversion = startTime.Format(format)\n\t}\n\n\treturn","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/cli/commands.go#L35-L71","documentation":"When creating a seq migration with a fixed digit width (`-seqdigits N`), the computed next sequence number, zero-padded to N digits, exceeds that width (e.g. 100000 with 5 digits). The CLI rejects the creation instead of emitting a version wider than configured, which would break lexicographic ordering assumptions.","triggerScenarios":"`migrate create -seq -seqdigits N ...` when the largest existing migration's sequence is >= 10^N - 1, so the incremented number no longer fits in N digits.","commonSituations":"Long-lived project that outgrew the default/forced digit width; someone lowered -seqdigits below the existing max sequence; a huge hand-written sequence number in an existing file pushes nextSeq over the cap.","solutions":["Increase the digit width, e.g. `migrate create -seq -seqdigits 6 ...`, so the next number fits (existing shorter files still sort correctly due to zero-padding).","Remove or renumber old migrations if they are no longer needed (only if safe — migrations may already be applied).","Check the highest sequence number in the directory and confirm it against the configured width before creating more migrations.","Switch to timestamp versions (`-format`) for new migrations if sequence exhaustion keeps recurring, accepting the mixed-format implications."],"exampleFix":"// before\nmigrate create -seq -seqdigits 5 -ext sql -name add_index\n// after (00000 max reached)\nmigrate create -seq -seqdigits 6 -ext sql -name add_index","handlingStrategy":"validation","validationCode":"maxSeq := 0\nfor _, f := range migrationFiles {\n    n, _ := strconv.Atoi(strings.SplitN(filepath.Base(f), \"_\", 2)[0])\n    if n > maxSeq { maxSeq = n }\n}\nif maxSeq+1 >= int(math.Pow10(seqDigits)) {\n    return fmt.Errorf(\"next seq %d will not fit in %d digits; increase -seqdigits\", maxSeq+1, seqDigits)\n}","typeGuard":null,"tryCatchPattern":"err := createCmd(dir, time.Now(), \"\", name, ext, true, seqDigits, true)\nif err != nil && strings.Contains(err.Error(), \"too large\") {\n    // rerun with a larger -seqdigits value\n}","preventionTips":["Pick a generous seqdigits (6-7) at project start.","Monitor the highest sequence number in review checklists/CI.","Don't lower -seqdigits below the current max sequence.","Consider timestamp versions for very long-lived projects."],"tags":["cli","migrations","sequence","versioning"],"backgroundTag":"sequence-number-overflow","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}