登录
首页 >  Golang >  Go问答

更改为使用 pgx 时 GORM 失败:migrator.go:206:65: undefined: gorm.ColumnType

来源:stackoverflow

时间:2024-04-13 22:18:34 273浏览 收藏

从现在开始,努力学习吧!本文《更改为使用 pgx 时 GORM 失败:migrator.go:206:65: undefined: gorm.ColumnType》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!

问题内容

我在使用 gorm 的 go 项目中使用了这个:

import (
    (...)
    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/postgres"
)

func main() {
    (...)
    db, err := gorm.open("postgres", dsn)
    if err != nil {
        panic(err)
    }
    defer db.close()
}

我能够打开与数据库的连接并执行所有事务。如果我更改为:

import (
    (...)
    "github.com/jinzhu/gorm"
    "gorm.io/driver/postgres"
)

func main(){
    (...)
    db, err := gorm.open(postgres.open(dsn), &gorm.config{})
    if err != nil {
        panic(err)
    }
    defer db.close()
}

它会给我一个关于go build的错误:

# gorm.io/driver/postgres
$GOPATH\pkg\mod\gorm.io\driver\[email protected]\migrator.go:206:65: undefined: gorm.ColumnType
$GOPATH\pkg\mod\gorm.io\driver\[email protected]\migrator.go:207:23: undefined: gorm.ColumnType

我从官方页面得到这个: https://gorm.io/docs/connecting_to_the_database.html


解决方案


我改用同一个库......我的错。 而不是

"github.com/jinzhu/gorm"

使用这个:

"gorm.io/gorm"

沿着同一个司机 所以现在看起来像这样:

import (
    (...)
    "gorm.io/gorm"
    "gorm.io/driver/postgres"
)

func main(){
    (...)
    db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
    if err != nil {
        panic(err)
    }
    defer db.Close()
}

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《更改为使用 pgx 时 GORM 失败:migrator.go:206:65: undefined: gorm.ColumnType》文章吧,也可关注golang学习网公众号了解相关技术文章。

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