首页 > 文章列表 > 使用 gin 和 gorm,如何为 Postgres 安装驱动程序?

使用 gin 和 gorm,如何为 Postgres 安装驱动程序?

498 2024-02-19
问题内容

我尝试将 gin 应用程序连接到 postgres 数据库,两者都是 docker 化的。我在安装 postgres 驱动程序时遇到错误。网站上描述了配置:

$ go get -u gorm.io/driver/postgres
go: downloading gorm.io/gorm v1.24.2
go: downloading github.com/jackc/pgx/v5 v5.3.1
go: downloading github.com/jackc/pgx v3.6.2+incompatible
gorm.io/driver/postgres imports
        github.com/jackc/pgx/v5 imports
        github.com/jackc/pgx/v5/pgtype imports
        net/netip: package net/netip is not in goroot (/usr/local/go/src/net/netip)

goroot 中似乎没有 net/netip 包。我发现它默认应该在这里。发生了什么?

我的go版本是1.17.6

$ go version
go version go1.17.6 linux/amd64


正确答案


至少升级到1.18版本,可能就是这个问题