0

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?

2
  • 1
    It should be postgres://postgres:postgres@localhost:5439/basename?sslmode=disable, read the doc carefully. Commented Aug 18, 2020 at 12:37
  • @Зелёный these entries are equivalent (I checked it just in case: error: database driver: unknown driver postgres (forgotten import?)) Commented Aug 18, 2020 at 14:12

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

For new versions of Golang(Go 1.16+)

  1. If you want to installed Versioned version e.g:

$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@$TAG

Where TAG=v4.1.0 or TAG=v4.1.x etc

  1. If you want to installed Unversioned version e.g:

$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.