go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.88k stars 3.93k forks source link

unsupported Scan, storing driver.Value type []uint8 into type *time.Time #6242

Open congjunhua opened 1 year ago

congjunhua commented 1 year ago

Your Question

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

The document you expected this should be explained

Expected answer

如何解决?

congjunhua commented 1 year ago

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

望早日修复。

black-06 commented 1 year ago

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

congjunhua commented 1 year ago

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

用了,但不起作用。

black-06 commented 1 year ago

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

BluesFu commented 1 year ago

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

kkk-zxx commented 1 month ago

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

black-06 commented 1 month ago

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

BluesFu commented 1 month ago

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