hasura/graphql-engine · error

applying migrations on source: %s: %w

Error message

applying migrations on source: %s: %w

What it means

During `hasura init --endpoint <url>` with metadata/migrations fetch, applying fetched migrations to a named source failed; the CLI collects per-source errors and wraps them as 'applying migrations on source: <name>'.

Source

Thrown at cli/commands/init.go:575

		if err != nil {
			context.err = err
			context.logger.Debugf(
				"getting list of connected databases from server (%s) failed",
				context.initOps.Endpoint,
			)

			return createMigrationFailed
		}

		for _, source := range sources {
			opts.EC.Logger.Infof("Creating migrations for source: %s", source.Name)
			opts.Source = cli.Source(source)

			_, err := opts.run()
			if err != nil {
				errs = append(
					errs,
					fmt.Errorf("applying migrations on source: %s: %w", source.Name, err),
				)
			}
		}
	}

	if len(errs) > 0 {
		context.err = stderrors.Join(errs...)

		return createMigrationFailed
	}

	return gotoEndstate
}

type failedCreatingMigrationAction struct{}

func (a *failedCreatingMigrationAction) Execute(ctx fsm.EventContext) eventType {
	context := ctx.(*initCtx)

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Verify network reachability and credentials for the specific source database named in the error
  2. Use --dry-run style inspection or fetch metadata/migrations without applying, then apply manually with fixes
  3. Resolve migration version conflicts on the target (mark applied or adjust down migrations)
  4. Retry init from an environment with access to the source DB
Defensive patterns

Strategy: retry

Validate before calling

// verify source DB reachability before init --endpoint
if _, err := net.DialTimeout("tcp", sourceDbHost+":"+sourceDbPort, 5*time.Second); err != nil {
    log.Fatal("source DB unreachable from this environment")
}

Try / catch

for attempt := 1; attempt <= 3; attempt++ {
    if err := initRun(); err != nil && strings.Contains(err.Error(), "applying migrations on source") {
        time.Sleep(time.Duration(attempt) * 2 * time.Second)
        continue
    } else if err != nil { break }
}

Prevention

When it happens

Trigger: Init from an endpoint where the source database is unreachable from your machine, admin secret invalid for the source, or a fetched migration fails to apply (version conflict, incompatible SQL).

Common situations: Source DB behind a firewall not reachable from the init environment; server requires credentials the CLI lacks; migrations reference objects existing only on the server's source; clock/version conflicts causing 'migration already applied' style failures.

Related errors


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