hasura/graphql-engine · error
up migration with SQL string could not be created: %w
Error message
up migration with SQL string could not be created: %w
What it means
With --up (SQL string flag), migrate create calls createOptions.SetSQLUp(o.upSQL). This wraps failures validating/storing the provided SQL string, most commonly an empty string.
Source
Thrown at cli/commands/migrate_create.go:265
return 0, herrors.E(op, fmt.Errorf("cannot fetch schema dump: %w", err))
}
err = createOptions.SetSQLUp(string(data))
if err != nil {
return 0, herrors.E(
op,
fmt.Errorf("while writing data from server into the up.sql file: %w", err),
)
}
}
// create pure sql based migrations here
if o.upSQLChanged {
err = createOptions.SetSQLUp(o.upSQL)
if err != nil {
return 0, herrors.E(
op,
fmt.Errorf("up migration with SQL string could not be created: %w", err),
)
}
}
if o.downSQLChanged {
err = createOptions.SetSQLDown(o.downSQL)
if err != nil {
return 0, herrors.E(
op,
fmt.Errorf("down migration with SQL string could not be created: %w", err),
)
}
}
if o.sqlFile == "" && !o.sqlServer && o.EC.Config.Version != cli.V1 {
// Set empty data for [up|down].sql
if !o.upSQLChanged {
createOptions.SQLUp = []byte(``)View on GitHub (pinned to 724551b9ae)
Solutions
- Echo the variable before running to confirm non-empty SQL is passed
- Quote the SQL argument properly (single quotes for SQL with double quotes)
- Provide both --up and --down if generating reversible migrations
Example fix
# before hasura migrate create add-col --up "$SQL" # SQL unset # after SQL='ALTER TABLE users ADD COLUMN email text;' hasura migrate create add-col --up "$SQL"
Defensive patterns
Strategy: validation
Validate before calling
[ -n "$(echo "$UP_SQL" | tr -d '[:space:]')" ] || { echo 'empty --up'; exit 1; } Prevention
- set -u in scripts to catch unset SQL variables
- Echo SQL vars before invoking the CLI
When it happens
Trigger: `hasura migrate create X --up ""` or --up set to whitespace-only SQL; also flag parsing edge cases where the value didn't reach the option.
Common situations: Shell quoting bugs passing an empty variable: --up "$SQL" with SQL unset.
Related errors
- down migration with SQL string could not be created: %w
- expected 0 arguments, found: %v
- error validating flags: %w
- not a valid input for steps/version: %w
- cannot create migrate instance: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/79dcb7ac00e19758.
Report an issue: GitHub.