ory/hydra · error

problem with migration

Error message

problem with migration

What it means

Status() queries all applied versions with 'SELECT version FROM <schema_migration table>'. If that query fails with anything other than 'table not found' (which is treated as 'nothing applied yet'), the error is unexpected and Status gives up, wrapping it with 'problem with migration'. It guards the happy path: table-not-found is fine on a fresh database, any other failure indicates a real database problem reading the migration bookkeeping table.

Source

Thrown at oryx/popx/migrator.go:633

	dialect := mb.c.Dialect.Name()
	fallbacks := mb.migrationFallbacks()
	migrationsUp := mb.migrationsUp.sortAndFilter(dialect, fallbacks...)

	if len(migrationsUp) == 0 {
		return nil, errors.Errorf("unable to find any migrations for dialect: %s", dialect)
	}

	alreadyApplied := make([]string, 0, len(migrationsUp))
	err := con.RawQuery(fmt.Sprintf("SELECT version FROM %s", sanitizedMigrationTableName(con))).All(&alreadyApplied)
	if err != nil {
		if errIsTableNotFound(err) {
			// This means that no migrations have been applied and we need to apply all of them first!
			//
			// It also means that we can ignore this state and act as if no migrations have been applied yet.
		} else {
			// On any other error, we fail.
			return nil, errors.Wrap(err, "problem with migration")
		}
	}

	statuses := make(MigrationStatuses, len(migrationsUp))
	for k, mf := range migrationsUp {
		downContent := "-- error: no down migration defined for this migration"
		if mDown := mb.migrationsDown.find(mf.Version, dialect, fallbacks...); mDown != nil {
			downContent = mDown.Content
		}
		statuses[k] = MigrationStatus{
			State:       Pending,
			Version:     mf.Version,
			Name:        mf.Name,
			ContentUp:   mf.Content,
			ContentDown: downContent,
		}

		if slices.ContainsFunc(alreadyApplied, func(applied string) bool {

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Inspect the wrapped inner error for the actual database cause.
  2. Verify the database user has SELECT privilege on the schema_migration table.
  3. Confirm the schema_migration table still has its 'version' column (revert manual modifications or restore from a backup).
  4. Check connectivity/pool health and ensure the context passed to Status is not cancelled or near its deadline.
  5. If the table truly does not exist but the error message differs (unsupported driver error text), run CreateSchemaMigrations first to bootstrap it.

Example fix

// before: user lacks SELECT on bookkeeping table
GRANT SELECT ON schema_migration TO app_user;
// after: Status query succeeds
statuses, err := mb.Status(ctx)
Defensive patterns

Strategy: try-catch

Validate before calling

// verify SELECT access on the bookkeeping table before calling Status
if err := c.RawQuery("SELECT 1 FROM schema_migration LIMIT 1").Exec(); err != nil && !isTableNotFound(err) {
    return fmt.Errorf("cannot read schema_migration: %w — check privileges/connectivity", err)
}

Try / catch

statuses, err := mb.Status(ctx)
if err != nil && strings.Contains(err.Error(), "problem with migration") {
    // unexpected DB failure reading migration table: log cause, check privileges/connections
    log.Printf("migration status read failed: %+v", err)
    return err
}

Prevention

When it happens

Trigger: Calling MigrationBox.Status(ctx) when the SELECT version FROM <migration_table> query fails with an error that does not match errIsTableNotFound's patterns ('no such table:', MySQL Error 1146, SQLSTATE 42P01) — e.g. permission denied, connection failure, query timeout/cancellation, or a corrupted migration table with an unexpected schema.

Common situations: The DB user can connect but lacks SELECT privilege on the schema_migration table; the database was restarted or the connection pool broke mid-query; a context timeout cancels the query; the table exists but was manually altered so 'version' column is missing; TLS/network flakiness in CI.

Related errors


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/a59e8ff236f55b16. Report an issue: GitHub.