#820·dbmate

Error on multiple migrations in a single file

Author: akhayyatCreated Jul 31, 2026Updated Sep 11, 2026
Labelsbug

Description

Using multiple migrations in a single file using additional migrate:up and migrate:down sections, I get the error:

Error: pq: duplicate key value violates unique constraint "schema_migrations_pkey" (23505)

Moreover, the file containing multiple migrations is reported as applied in dbmate status. In reality, only the first migration (-- migrate:up block) is applied.

  • Version: 2.34.1
  • Database: PostgreSQL
  • Operating System: Debian

Steps To Reproduce

  1. Use this migration file:
sql
-- migrate:up
CREATE TABLE t1 (
    col_a text
);

-- migrate:down
DROP TABLE t1;

-- migrate:up
CREATE TABLE t2 (
    col_b text
);

-- migrate:down
DROP TABLE t2;
  1. Run dbmate migrate

Expected Behavior

Successful migration