簡體   English   中英

更改為使用 pgx 時 GORM 失敗:migrator.go:206:65: undefined: gorm.ColumnType

[英]GORM failed when changing to using pgx: migrator.go:206:65: undefined: gorm.ColumnType

我在我的 go 項目中使用了 GORM:

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\postgres@v1.0.5\migrator.go:206:65: undefined: gorm.ColumnType
$GOPATH\pkg\mod\gorm.io\driver\postgres@v1.0.5\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()
}

您可能需要升級到更新版本的 gorm。 使用v1.20.4時出現此錯誤。 gorm.io/gorm v1.20.7適合我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM