Search code examples
postgresqlgomigrationgolang-migrate

golang-migrate unknown driver postgresql using terminal command


When I try to migrate down my base using terminal command (migrate -path scripts -database "postgresql://postgres:postgres@localhost:5439/basename?sslmode=disable" -verbose down) I got an error: error: database driver: unknown driver postgresql (forgotten import?). How to fix it?


Solution

  • I think you need to build with specific tag to add the specific driver.

    See documentation https://github.com/golang-migrate/migrate/tree/master/cmd/migrate#with-go-toolchain

    $ go get -u -d github.com/golang-migrate/migrate/cmd/migrate
    $ cd $GOPATH/src/github.com/golang-migrate/migrate/cmd/migrate
    $ git checkout $TAG  # e.g. v4.1.0
    $ go build -tags 'postgres' -ldflags="-X main.Version=$(git describe --tags)" -o $GOPATH/bin/migrate $GOPATH/src/github.com/golang-migrate/migrate/cmd/migrate