在Go/Golang中的构建错误:Column未实现gorm.ColumnType(缺少AutoIncrement方法)

huangapple go评论221阅读模式
英文:

Build error in Go/Golang: Column does not implement gorm.ColumnType (missing AutoIncrement method)

问题

我在 Golang V1.17 中间时不时遇到这个构建错误。

# gorm.io/driver/mysql
../../../../pkg/mod/gorm.io/driver/mysql@v1.2.1/migrator.go:224:24: cannot use column (type Column) as type gorm.ColumnType in append:
        Column does not implement gorm.ColumnType (missing AutoIncrement method)

我已经尝试过重新启动、清除 VS Code 的缓存、删除 go.mod 和 go.sum 等等。

是否有解决方法或其他办法?

英文:

I am facing this build error in Golang V1.17 intermittently.

# gorm.io/driver/mysql
../../../../pkg/mod/gorm.io/driver/mysql@v1.2.1/migrator.go:224:24: cannot use column (type Column) as type gorm.ColumnType in append:
        Column does not implement gorm.ColumnType (missing AutoIncrement method)

I have tried restarting, clearing cache on VS Code, deleting go.mod and go.sum, and what-not.

Is there a workaround or something?

答案1

得分: 9

你的问题通过安装 GORM 的 MySQL 驱动程序得到了解决:

~ go get gorm.io/driver/mysql
英文:

my problem solved by installing mysql driver for gorm:

~  go get gorm.io/driver/mysql

答案2

得分: 5

我通过更新所有相关的包来解决了这个问题,它起作用了:

go get gorm.io/gorm
go get gorm.io/driver/mysql
go get gorm.io/driver/sqlserver
go get gorm.io/driver/postgres

go mod vendor
英文:

I solve it by update all relative package,it works:

go get gorm.io/gorm
go get gorm.io/driver/mysql
go get gorm.io/driver/sqlserver
go get gorm.io/driver/postgres

go mod vendor

答案3

得分: 3

这是跟随go-gorm/gorm问题5096的步骤,其中包括:

> 我使用以下命令更新了最新的gorm模块:
>bash >rm -rf go.mod go.sum >go mod init "panel" # <== 替换为您自己的项目名称 >go mod tidy >go mod vendor >
>运行错误后,替换版本就可以了。
>bash >go mod edit -require=gorm.io/driver/mysql@v1.2.3 >go mod edit -require=gorm.io/gorm@v1.22.5 >go mod vendor >

英文:

This is followed by go-gorm/gorm issue 5096 which includes:

> I update the latest gorm module with the following command:
>bash
>rm -rf go.mod go.sum
>go mod init "panel" # <== replace by your own project name
>go mod tidy
>go mod vendor
>

>After running the error, the replacement version is fine.
>bash
>go mod edit -require=gorm.io/driver/mysql@v1.2.3
>go mod edit -require=gorm.io/gorm@v1.22.5
>go mod vendor
>

huangapple
  • 本文由 发表于 2022年3月8日 14:52:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/71391062.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定