登录
首页 >  Golang >  Go问答

golang-使用终端命令迁移未知驱动程序 postgresql

来源:stackoverflow

时间:2024-03-31 20:33:35 114浏览 收藏

大家好,今天本人给大家带来文章《golang-使用终端命令迁移未知驱动程序 postgresql》,文中内容主要涉及到,如果你对Golang方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!

问题内容

当我尝试使用终端命令(migrate -path scripts -database "postgresql://postgres:postgres@localhost:5439/basename?sslmode=disable" -verbose down)向下迁移我的库时,出现错误:error :数据库驱动程序:未知驱动程序postgresql(忘记导入?)。如何解决?


解决方案


我认为您需要使用特定标签进行构建以添加特定驱动程序。

查看文档 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

适用于新版本的golang(go 1.16+)

  1. 如果您想安装版本化版本,例如:

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

其中 tag=v4.1.0tag=v4.1.x

  1. 如果您想安装无版本版本,例如:

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

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>