I'm using MySQL 5.6.10, and the DATETIME fields are throwing this error when following the same format from your example:
type User struct {
Id int64
CreatedAt time.Time
}
The error thrown is:
sql: Scan error on column index 2: unsupported driver -> Scan pair: []uint8 -> *time.Time
This is complaining that the field is actually a string. Using string as the type sends the string equivalent of the datetime
2013-07-25 22:48:23
I can workaround this by just casting it to a time.Time myself but you may want to fix this issue. The driver I'm using the is typical one https://github.com/go-sql-driver/mysql.
I've made sure the field is indeed of type DATETIME in my database.
Let me know if you need any other information.
Did you open mysql with parseTime option like this?
db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")
No news is good news, feel free to reopen it if still have any issue.
parseTime=True fixed the issue for me, thanks!.
It works!!!
Thanks
Most helpful comment
Did you open mysql with parseTime option like this?
db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")