hasura/graphql-engine · error

cannot set sql file: %w

Error message

cannot set sql file: %w

What it means

With --sql-file set, migrate create calls createOptions.SetSQLUpFromFile to read the given file into the up migration. This wraps file-read or content-validation failures (file missing, unreadable, or empty/invalid).

Source

Thrown at cli/commands/migrate_create.go:235

	if o.fromServer {
		o.sqlServer = true
	}

	var migrateDrv *migrate.Migrate
	// disabling auto state migrations for migrate create command
	o.EC.DisableAutoStateMigration = true
	if o.sqlServer || o.upSQLChanged || o.downSQLChanged {
		migrateDrv, err = migrate.NewMigrate(o.EC, true, o.Source.Name, o.Source.Kind)
		if err != nil {
			return 0, herrors.E(op, fmt.Errorf("cannot create migrate instance: %w", err))
		}
	}

	if o.sqlFile != "" {
		// sql-file flag is set
		err := createOptions.SetSQLUpFromFile(o.sqlFile)
		if err != nil {
			return 0, herrors.E(op, fmt.Errorf("cannot set sql file: %w", err))
		}
	}

	if o.sqlServer {
		data, err := migrateDrv.ExportSchemaDump(
			o.includeSchemas,
			o.excludeSchemas,
			o.Source.Name,
			o.Source.Kind,
		)
		if err != nil {
			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,

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Check the path exists and is readable: cat <path> from the same directory you run the CLI
  2. Use an absolute path in scripts
  3. Ensure the SQL file is non-empty and valid

Example fix

# before
hasura migrate create fix-users --sql-file users.sql   # file actually in sql/users.sql
# after
hasura migrate create fix-users --sql-file sql/users.sql
Defensive patterns

Strategy: validation

Validate before calling

test -s "$SQLFILE" || { echo "sql file missing/empty"; exit 1; }

Prevention

When it happens

Trigger: `hasura migrate create X --sql-file path/to/file.sql` where the path doesn't exist, lacks read permission, or the file content fails validation (e.g. empty).

Common situations: Relative path resolved from a different working directory; typo in filename; file generated by a previous step that failed silently.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/736acb052ebb974e. Report an issue: GitHub.