Your Question

Mysql中的TIME类型的字段映射Gotime.Time类型时报标题错误。

The document you expected this should be explained

Expected answer

如何解决?

Comment From: congjunhua

time.Time改为string可以规避报错,虽然不合理且徒增了类型转化的步骤,但暂时也只能这样了。

望早日修复。

Comment From: black-06

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

Comment From: congjunhua

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

用了,但不起作用。

Comment From: black-06

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

用了,但不起作用。

Could you provide more detailed information

Comment From: BluesFu

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

thanks, it works well

Comment From: kkk-zxx

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

用了,但不起作用。

Could you provide more detailed information

parseTime=True. is support Mysql date and datetime , not support time

Comment From: black-06

You can try parseTime=True in your DSN, just like gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local

用了,但不起作用。

Could you provide more detailed information

parseTime=True. is support Mysql date and datetime , not support time

Yes, because github.com/go-sql-driver/mysql does not support time, see https://github.com/go-sql-driver/mysql/issues/849#issuecomment-416943196 and https://github.com/go-sql-driver/mysql/issues/849#issuecomment-417209270.

~~If you want to convert MySQL's Time to time.Time, this is an example:~~

if you want to MySQL's Time to time.Duration, you can use gorm.io/datatypes, see https://github.com/go-gorm/datatypes/blob/master/time.go. Similar, so you can also convert it to time.Time

Comment From: BluesFu

https://github.com/golang-module/carbon time.Time 的替代方案,gorm兼容性非常好