ory/hydra · error
problem checking for legacy migration version %s
Error message
problem checking for legacy migration version %s
What it means
If a migration's full-length version is not found in schema_migration, the migrator also probes the legacy 14-char truncated version. This error wraps a failure of that legacy EXISTS lookup. It is a query failure against the tracking table, not evidence about whether the legacy row exists.
Source
Thrown at oryx/popx/migrator.go:379
mb.l.WithError(err).Error("Problem reverting migrations.")
}
}()
for i, mi := range mfs {
if i >= attemptSteps {
break
}
l := mb.l.WithField("version", mi.Version).WithField("migration_name", mi.Name).WithField("migration_file", mi.Path)
l.Debugf("handling migration %s", mi.Name)
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
if !exists && len(mi.Version) > 14 {
legacyVersion := mi.Version[:14]
legacyVersionExists, err := c.Where("version = ?", legacyVersion).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for legacy migration version %s", legacyVersion)
}
if !legacyVersionExists {
return errors.Errorf("neither normal (%s) nor legacy migration (%s) exist", mi.Version, legacyVersion)
}
} else if !exists {
return errors.Errorf("migration version %s does not exist", mi.Version)
}
if err := mi.Valid(); err != nil {
return errors.WithStack(err)
}
if mb.shouldNotUseTransaction(mi) {
err := mi.Runner(mi, c)
if err != nil {
return errors.WithStack(err)
}View on GitHub (pinned to 4174065ffb)
Solutions
- Inspect the wrapped cause for the underlying SQL error
- Verify schema_migration exists and is readable
- Reconnect/retry once the database is reachable
Defensive patterns
Strategy: retry
Validate before calling
var n int
if err := db.QueryRow("SELECT COUNT(*) FROM schema_migration").Scan(&n); err != nil {
return fmt.Errorf("tracking table unreadable before Down: %w", err)
} Try / catch
if err := box.Down(ctx, 1); err != nil {
if isTransient(err) {
time.Sleep(time.Second)
return box.Down(ctx, 1)
}
return err
} Prevention
- Check DB connectivity before starting rollback runs
- Do not drop schema_migration mid-operation
- Ensure consistent read access for the migration user
When it happens
Trigger: Calling Down for a migration with a version longer than 14 characters whose full version is absent, and the legacy-version EXISTS query fails (table missing, connection error, permissions).
Common situations: schema_migration dropped or corrupted between queries; transient connection failure; wrong database (table absent).
Related errors
- problem inserting migration version %s
- problem inserting migration version %s. YOUR DATABASE MAY BE
- migration down: unable count existing migration
- neither normal (%s) nor legacy migration (%s) exist
- migration version %s does not exist
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/cbe35363f865b5ee.
Report an issue: GitHub.