Skip to content

Migration fails when no schema_migrations table exists #1246

Open
@K1DV5

Description

@K1DV5

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:
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:
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions