当我尝试使用终端命令(migrate -path scripts -database "postgresql://postgres:postgres@localhost:5439/basename?sslmode=disable" -verbose down
(向下迁移时,我得到了一个错误:error: database driver: unknown driver postgresql (forgotten import?)
。如何修复?
我认为您需要使用特定的标签来添加特定的驱动程序。
请参阅文档https://github.com/golang-migrate/migrate/tree/master/cmd/migrate#with-去工具链
$ 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
对于Golang(Go 1.16+(的新版本
- 如果您想安装版本版本,例如:
$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@$TAG
其中TAG=v4.1.0
或TAG=v4.1.x
等
- 如果您想安装未版本的版本,例如:
$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest