golang-migrate/migrate · error
-all cannot be used with other arguments
Error message
-all cannot be used with other arguments
What it means
numDownMigrationsFromArgs returns the error '-all cannot be used with other arguments' when `migrate down -all` is invoked together with an extra positional argument. The -all flag means 'down all migrations' and is therefore incompatible with an explicit limit N; the CLI surfaces this to force an unambiguous command.
Source
Thrown at internal/cli/commands.go:230
func versionCmd(m *migrate.Migrate) error {
v, dirty, err := m.Version()
if err != nil {
return err
}
if dirty {
log.Printf("%v (dirty)\n", v)
} else {
log.Println(v)
}
return nil
}
// numDownMigrationsFromArgs returns an int for number of migrations to apply
// and a bool indicating if we need a confirm before applying
func numDownMigrationsFromArgs(applyAll bool, args []string) (int, bool, error) {
if applyAll {
if len(args) > 0 {
return 0, false, errors.New("-all cannot be used with other arguments")
}
return -1, false, nil
}
switch len(args) {
case 0:
return -1, true, nil
case 1:
downValue := args[0]
n, err := strconv.ParseUint(downValue, 10, 64)
if err != nil {
return 0, false, errors.New("can't read limit argument N")
}
return int(n), false, nil
default:
return 0, false, errors.New("too many arguments")
}
}View on GitHub (pinned to 01a9643f14)
Solutions
- Use `migrate down -all` alone to revert everything, or `migrate down N` without -all to revert N migrations.
- Remove the extra positional argument from the command line/script.
- Guard in wrapper scripts: if -all is present, drop any positional args.
- Check shell variables/quoting so they don't inject an unexpected argument.
Example fix
// before migrate -path ./migrations -database $DB down -all 2 // after migrate -path ./migrations -database $DB down -all # or: down 2 without -all
Defensive patterns
Strategy: validation
Validate before calling
ARGS=$(cat) if grep -q -- '-all' <<< "$ARGS" && [ $(wc -w <<< "$POSITIONAL") -gt 0 ]; then echo "-all cannot be combined with positional arguments"; exit 1 fi
Prevention
- Choose either -all or a count N — never both
- Separate flags from positional args in wrapper scripts and drop positionals when -all is set
- Read migrate's CLI help for the down subcommand to confirm accepted forms
When it happens
Trigger: Running `migrate -source file -path . down -all 2` — the -all flag combined with one or more positional args (len(args) > 0 when applyAll is true).
Common situations: Script templates appending an argument for other subcommands while -all is still present; users unsure whether to use -all or N and passing both; shell variable expansion that appends an empty-but-counted argument.
Related errors
- the seq and format options are mutually exclusive
- digits must be positive
- time format may not be empty
- can't read limit argument N
- too many arguments
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/b8d84e8122aa23b4.
Report an issue: GitHub.