ory/hydra · error
could not execute migration template %s
Error message
could not execute migration template %s
What it means
After parsing, the template is executed with a data struct (IsSQLite, IsCockroach, IsMySQL, IsMariaDB, IsPostgreSQL, DialectDetails, Parameters). If t.Execute fails while rendering the migration for the current dialect, the error is wrapped with 'could not execute migration template %s'.
Source
Thrown at oryx/popx/migration_content.go:45
err = t.Execute(&bb, struct {
IsSQLite bool
IsCockroach bool
IsMySQL bool
IsMariaDB bool
IsPostgreSQL bool
DialectDetails *pop.ConnectionDetails
Parameters map[string]interface{}
}{
IsSQLite: c.Dialect.Name() == "sqlite3",
IsCockroach: c.Dialect.Name() == "cockroach",
IsMySQL: c.Dialect.Name() == "mysql",
IsMariaDB: c.Dialect.Name() == "mariadb",
IsPostgreSQL: dbal.IsPostgresCompatible(c.Dialect.Name()),
DialectDetails: c.Dialect.Details(),
Parameters: params,
})
if err != nil {
return "", errors.Wrapf(err, "could not execute migration template %s", mf.Path)
}
content = bb.String()
} else {
content = string(b)
}
return content, nil
}
}
View on GitHub (pinned to 4174065ffb)
Solutions
- Check the template references only provided fields: IsSQLite, IsCockroach, IsMySQL, IsMariaDB, IsPostgreSQL, DialectDetails, Parameters
- Fix field-name typos in the migration template
- Inspect the wrapped cause for custom function failures and fix that function
- Render the template locally with a small Go snippet against the same data to reproduce
Example fix
// before (migration template)
{{ .IsPostgres }}
// after
{{ .IsPostgreSQL }} Defensive patterns
Strategy: validation
Validate before calling
// Execute the template with representative data before deploying
func templateExecutes(path string) error {
b, _ := os.ReadFile(path)
t, err := template.New("check").Funcs(popx.SQLTemplateFuncs).Parse(string(b))
if err != nil { return err }
return t.Execute(io.Discard, map[string]any{
"IsSQLite": true, "IsCockroach": false, "IsMySQL": false,
"IsMariaDB": false, "IsPostgreSQL": false, "DialectDetails": nil, "Parameters": nil,
})
} Prevention
- Reference only fields present in the execution data struct
- Test templated migrations against every dialect your app supports
- Update templates whenever the data struct fields change
- Keep dialect branches ({{ if .IsMySQL }}) individually tested
When it happens
Trigger: A template referencing a field/function missing from the execution data struct (e.g. {{ .Foo }}), or a custom SQLTemplateFuncs function returning an error during Execute for a specific dialect.
Common situations: Renaming struct fields without updating migration templates; a dialect-specific helper failing; typos in field names like {{ .IsPostgres }} instead of {{ .IsPostgreSQL }}.
Related errors
- could not parse template %s
- migration %s has no corresponding down migration
- problem checking for migration version %s
- unsupported dialect
- error processing %s
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/6f9f4dd5d5de4080.
Report an issue: GitHub.