{"record":{"id":"79dcb7ac00e19758","repo":"hasura/graphql-engine","slug":"up-migration-with-sql-string-could-not-be-created","errorCode":null,"errorMessage":"up migration with SQL string could not be created: %w","messagePattern":"up migration with SQL string could not be created: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/migrate_create.go","lineNumber":265,"sourceCode":"\t\t\treturn 0, herrors.E(op, fmt.Errorf(\"cannot fetch schema dump: %w\", err))\n\t\t}\n\n\t\terr = createOptions.SetSQLUp(string(data))\n\t\tif err != nil {\n\t\t\treturn 0, herrors.E(\n\t\t\t\top,\n\t\t\t\tfmt.Errorf(\"while writing data from server into the up.sql file: %w\", err),\n\t\t\t)\n\t\t}\n\t}\n\n\t// create pure sql based migrations here\n\tif o.upSQLChanged {\n\t\terr = createOptions.SetSQLUp(o.upSQL)\n\t\tif err != nil {\n\t\t\treturn 0, herrors.E(\n\t\t\t\top,\n\t\t\t\tfmt.Errorf(\"up migration with SQL string could not be created: %w\", err),\n\t\t\t)\n\t\t}\n\t}\n\n\tif o.downSQLChanged {\n\t\terr = createOptions.SetSQLDown(o.downSQL)\n\t\tif err != nil {\n\t\t\treturn 0, herrors.E(\n\t\t\t\top,\n\t\t\t\tfmt.Errorf(\"down migration with SQL string could not be created: %w\", err),\n\t\t\t)\n\t\t}\n\t}\n\n\tif o.sqlFile == \"\" && !o.sqlServer && o.EC.Config.Version != cli.V1 {\n\t\t// Set empty data for [up|down].sql\n\t\tif !o.upSQLChanged {\n\t\t\tcreateOptions.SQLUp = []byte(``)","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/migrate_create.go#L247-L283","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Shell quoting bugs passing an empty variable: --up \"$SQL\" with SQL unset.","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"],"exampleFix":"# before\nhasura migrate create add-col --up \"$SQL\"   # SQL unset\n# after\nSQL='ALTER TABLE users ADD COLUMN email text;'\nhasura migrate create add-col --up \"$SQL\"","handlingStrategy":"validation","validationCode":"[ -n \"$(echo \"$UP_SQL\" | tr -d '[:space:]')\" ] || { echo 'empty --up'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["set -u in scripts to catch unset SQL variables","Echo SQL vars before invoking the CLI"],"tags":["migrate-create","sql-validation","cli-usage"],"backgroundTag":"empty-migration-sql","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}