Migrate: Dirty Database version 1 issue prevents migrations from running

Created on 6 Jan 2020  路  3Comments  路  Source: golang-migrate/migrate

Describe the Bug
Migrations do not run due to the following error message

Dirty database version 1. Fix and force version.

Steps to Reproduce
I have created my up and down sql migration scripts that begin something like this

CREATE database mydb;

USE mydb;

CREATE TABLE IF NOT EXISTS "mytable" (
  "id" int PRIMARY KEY,
  "day" date NOT NULL,
  "somefield" varchar NOT NULL
);

Here is the function that runs the migrations:

func RunMigrations() {
    m, err := migrate.New(
        "file://db/migrations",
        "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable")
    if err != nil {
        log.Fatal(err)
    }
    if err := m.Up(); err != nil {
        log.Fatal(err)
    }
}

Expected Behavior
Migrations should have been run with success

Migrate Version
4.7.1

Loaded Source Drivers
file

Loaded Database Drivers
postgres

Go Version
go version go1.13.1 darwin/amd64

Stacktrace

Dirty database version 1. Fix and force version.

Most helpful comment

@nickmurr try drop table schema_migrations; and the table will be recreated on next "first time" up

All 3 comments

Hey, did you fix this issue? Having the same problem

@nickmurr try drop table schema_migrations; and the table will be recreated on next "first time" up

@nickmurr try drop table schema_migrations; and the table will be recreated on next "first time" up

that was the best workaround (and perhaps solution) across all answers throughout the web

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pashagolub picture pashagolub  路  3Comments

dhui picture dhui  路  10Comments

chrism00ch picture chrism00ch  路  3Comments

segfault16 picture segfault16  路  9Comments

dcormier picture dcormier  路  6Comments