golang-migrate无法找到postgres驱动程序

氨酚:

在我的 internal/platform/database/database.go


import (
    "github.com/golang-migrate/migrate"
    "github.com/jmoiron/sqlx"
    _ "github.com/lib/pq"
)

func RunMigrations() error {
    m, err := migrate.New(
        "file://schema",
        "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable")
    if err != nil {
        return errors.Wrap(err, "error creating migrations object")
    }

从我调用此函数cmd/my-api/main.go如下:


import (
    _ "github.com/golang-migrate/migrate/v4/database/postgres"
    _ "github.com/golang-migrate/migrate/v4/source/file"
    "github.com/jmoiron/sqlx"
    _ "github.com/lib/pq"
    "github.com/myrepo/myproject/internal/platform/database"
)

    // =========================================================================
    // Executing migrations
    if err := database.RunMigrations(); err != nil {
        log.Fatal(err)
    }

尽管我postgres两个文件导入了驱动程序_ "github.com/lib/pq"

运行该程序失败,如下所示:

error creating migrations object: source driver: unknown driver file (forgotten import?)
exit status 1

这是为什么?

氨酚:

似乎golang-migrate需要其自己的相应驱动程序版本(?)

以下导入为我解决了

_ "github.com/golang-migrate/migrate/v4/database/postgres"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Jooq是无法找到Postgres数据库驱动程序

将UpdateOne与MongoDB Golang驱动程序一起使用时Upsert不起作用

导入mongo驱动程序golang时的net / http TLS握手超时

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

Golang MongoDB驱动程序排序

Golang mongo驱动程序性能

golang mysql驱动程序无法替换参数

在Golang MongoDb驱动程序中动态创建BSON

更新MongoDB和Golang驱动程序中的时间戳字段

Golang官方驱动程序中的MongoDB连接池

如何在golang lib / pq postgresql驱动程序中设置应用程序名称?

使用golang和sqlserver驱动程序查询参数

Golang驱动程序还是HTTP?

golang sql驱动程序的prepare语句

Google App Engine Golang,驱动程序:连接不良

Golang mssql驱动程序返回“ mssql:无效的对象名称”

如何在GoLang的不同处理程序上全局共享MySQL驱动程序

如何在golang rethinkdb驱动程序gorethink中重命名结果字段?

使用mgo驱动程序在golang中进行mongo聚合查询

可以在golang驱动程序中使用表上的OnChange-rethinkDB吗?

如何使用Go驱动程序或Golang在Mongodb中插入Javascritpt函数

如何使用golang mgo MongoDb驱动程序获取最后插入的ObjectId

Aerospike-如何使用golang驱动程序将BinMap转换为JSON

FlywayDB无法找到Postgresql驱动程序

Golang MongoDB驱动程序错误架构验证

PHP无法找到MongoDB驱动程序

Windows无法找到网络驱动程序

使用 postgres 驱动程序在 golang 中使用参数执行查询时出错

如何使用 mongo 驱动程序在 Golang 中实现 MongoDB 自动完成?