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

4.2k Views Asked by At

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

# gorm.io/driver/mysql
../../../../pkg/mod/gorm.io/driver/[email protected]/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?

3

There are 3 best solutions below

0
On

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
0
On

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

I update the latest gorm module with the following command:

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.

go mod edit -require=gorm.io/driver/[email protected]
go mod edit -require=gorm.io/[email protected]
go mod vendor
0
On

my problem solved by installing mysql driver for gorm:

~  go get gorm.io/driver/mysql