hasura/graphql-engine · error
%v not applied on database
Error message
%v not applied on database
What it means
Thrown during a down-migration when the CLI rewinds migrations: after applying version `from`, it asks the database driver for the previous applied version (Prev). If the database has no previous version but the migration source does report one (and the target isn't -1), the database and filesystem migration histories have diverged and the migration is aborted with '<version> not applied on database'. It protects against rolling back migrations the database doesn't know about.
Source
Thrown at cli/migrate/migrate.go:2199
ret <- migr
go func(migr *Migration, m *Migrate) {
err := migr.Buffer()
if err != nil {
m.Logger.Error(err)
}
}(migr, m)
from = database.NilVersion
continue
} else if err != nil {
ret <- err
return
}
ret <- fmt.Errorf("%v not applied on database", prev)
return
}
migr, err := m.newMigration(suint64(from), int64(prev.Version))
if err != nil {
ret <- err
return
}
ret <- migr
go func(migr *Migration, m *Migrate) {
err := migr.Buffer()
if err != nil {
m.Logger.Error(err)
}
}(migr, m)View on GitHub (pinned to 724551b9ae)
Solutions
- Compare `hasura migration status` output with files in migrations/ and fix the divergence (delete stray files or re-insert missing version rows)
- If the database is truly behind, run `hasura migrate apply` to bring it up to date before downgrading
- As a last resort, delete the migrations directory's extra versions or squash migrations and re-baseline the database (drop/recreate schema_migrations entries)
- Avoid editing hdb_catalog.schema_migrations by hand; use CLI commands only
Example fix
# before hasura migrate downgrade --to 12 # database history diverged from migrations/ # after hasura migration status # inspect divergence first hasura migrate apply # sync database, then downgrade
Defensive patterns
Strategy: validation
Validate before calling
// Before migrating, compare applied versions with source versions status, err := m.GetStatus() // or `hasura migration status` // ensure every version <= target exists in both source and database
Try / catch
if err := migrateInstance.Down(ctx, to); err != nil {
if strings.Contains(err.Error(), "not applied on database") {
// database/source histories diverged: run migration status and reconcile
}
} Prevention
- Never edit hdb_catalog.schema_migrations manually
- Use only CLI commands to create/apply/rollback migrations
- Run `hasura migration status` in CI before apply/downgrade
- Keep the migrations directory in version control and identical across environments
When it happens
Trigger: Running `hasura migrate downgrade`/`rollback` (Migrate.Down path in cli/migrate/migrate.go) when the versions recorded in hdb_catalog.schema_migrations / catalog state don't match the migrations present in the migrations/ directory — e.g. someone deleted rows from the migrations table or copied migrations files from another project.
Common situations: Manually editing or truncating the schema_migrations table; restoring a database dump without the migrations metadata; copying the migrations folder between environments; running downgrade after a partial/failed migration run.
Related errors
- unable to marshal run_sql args in %s: %w
- unable to unmarshal run_sql args in %s: %w
- creating Version table failed %s
- cannot create migration: %w
- database driver: unknown driver %v
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/97b6303bd93f0689.
Report an issue: GitHub.