hasura/graphql-engine · error
cannot create migration: %w
Error message
cannot create migration: %w
What it means
Returned by SquashCmd when creating the squashed migration files on disk fails after computing versions. The underlying createOptions.Create() error is wrapped with 'cannot create migration'.
Source
Thrown at cli/migrate/cmd/commands.go:260
from uint64,
to int64,
version int64,
name, directory string,
) (versions []int64, err error) {
var op errors.Op = "cmd.SquashCmd"
versions, upSql, downSql, err := m.Squash(from, to)
if err != nil {
return versions, errors.E(op, err)
}
createOptions := New(version, name, directory)
createOptions.SQLUp = upSql
createOptions.SQLDown = downSql
err = createOptions.Create()
if err != nil {
return versions, errors.E(op, fmt.Errorf("cannot create migration: %w", err))
}
return versions, nil
}
func GotoVersionCmd(m *migrate.Migrate, gotoVersion int64) error {
var op errors.Op = "cmd.GotoVersionCmd"
err := m.GotoVersion(gotoVersion)
if err != nil {
return errors.E(op, err)
}
return nil
}
View on GitHub (pinned to 724551b9ae)
Solutions
- Check the migrations directory is writable and the CLI is run from the project root
- Remove or rename leftover partially-created migration files from a failed squash, then retry
- Verify the --name flag produces a valid file name
- Re-run squash; versions are recomputed each attempt
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(migrationsDir)
if err != nil || !info.IsDir() { return fmt.Errorf("migrations dir missing") }
if err := os.WriteFile(filepath.Join(migrationsDir, ".probe"), nil, 0644); err != nil { return err }
os.Remove(filepath.Join(migrationsDir, ".probe")) Prevention
- Run squash from the project root with a writable migrations directory
- Clean up partial files after failed squash attempts before retrying
When it happens
Trigger: Running `hasura migrate squash` where writing the new migration files fails: unwritable migrations directory, a file with the same timestamp/version already exists, or invalid migration name.
Common situations: Read-only checkout, incorrect --name, running squash from the wrong directory, or leftover files from a previous squash attempt with the same version timestamp.
Related errors
- unable to move migrations from project for: %v : %w
- unable to create directory: %w
- generating docs failed: %w
- error getting current working directory: %w
- directory '%s' already exists
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/940a92af9682ee69.
Report an issue: GitHub.