#1246·migrate

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:

  1. My migrations look like:
sql
BEGIN;
create table foo(id integer);
COMMIT;
  1. I ran migrate with the following options: I created an instance of an *sql.DB using pgx/v5 and gave that instance to the pgx driver of migrate:
go
  driver, err := pgx.WithInstance(sqldb, &pgx.Config{})
  m, err := migrate.NewWithDatabaseInstance(
      "file://" + MIGRATIONS_DIR,
      "postgres", driver)
  1. 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