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

前端 未结 3 1389
借酒劲吻你
借酒劲吻你 2021-01-31 08:16

I have difficulty querieing for users, which is defined as:

type User struct {
    ID           int       `db:\"id\" json:\"id\"`            
    UserName     st         


        
相关标签:
3条回答
  • 2021-01-31 08:31

    In my case, I had a similar problem but for my particular usecase, it was a struct with a select which didn't work, since I only needed to select data, then I proceeded to simply:

    change the data type from time.Time to string

    This solved my problem, and I was able to get the data from the database. So perhaps it is not the best solution, but this is what worked for me.

    Mr Karlom's solution also worked for me, this is just an alternative method.

    0 讨论(0)
  • 2021-01-31 08:37

    Alright, I found the solution, thanks this answer. The problem goes by adding ?parseTime=true to the db mapper. Like this:

    db, err := sqlx.Connect("mysql", "myuser:mypass@tcp(127.0.0.1:3306)/mydb?parseTime=true")
    
    0 讨论(0)
  • 2021-01-31 08:42

    In my case, I'm change

    db, err := sql.Open("mysql", "root:@/?parseTime=true")
    

    Is resolve problem.

    0 讨论(0)
提交回复
热议问题