Migration fails when no schema_migrations table exists
Author: K1DV5Created Mar 12, 2025Updated Sep 22, 2026
Describe the Bug Trying to use migrate from inside the code with m.Up() results in the error "no migration" on an empty database.
Steps to Reproduce Steps to reproduce the behavior:
- My migrations look like:
BEGIN;
create table foo(id integer);
COMMIT;- I ran migrate with the following options: I created an instance of an
*sql.DBusingpgx/v5and gave that instance to the pgx driver of migrate:
driver, err := pgx.WithInstance(sqldb, &pgx.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file://" + MIGRATIONS_DIR,
"postgres", driver)- See error: "no migration" because there is no migration table. Also if the migration table exists and is empty, same thing happens. If I manually create and fill the table with the current version it works.
Expected Behavior Migration table should be created and populated automatically as stated in the FAQ.
Migrate Version v4.18.2 Obtained from go.mod
Loaded Source Drivers Filesystem/sql Obtained by running: I wrote sources and the above code
Loaded Database Drivers pgx Obtained by running: I wrote the above code
Go Version
e.g. go version go1.23.5 linux/amd64
Obtained by running: go version
Stacktrace None available
Additional context None
Source: golang-migrate/migrate