Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while retiring DATETIME field value from MySQL DB table #56

Closed
souravray opened this issue Jan 25, 2014 · 2 comments
Closed

Error while retiring DATETIME field value from MySQL DB table #56

souravray opened this issue Jan 25, 2014 · 2 comments

Comments

@souravray
Copy link

my model structure looks like bellow

type Status struct {
    Id          int64
    AuthorId int64
    Description string `sql:"size:255"`
    PublishDate   time.Time
}

When I create a new record & save

myStatus:= Status{
        AuthorId :  business1.Id,
        Description: "I got stuck here",
        PublishDate   :   time.Date(2013, time.January, 22, 23, 59, 59, 0, time.UTC),
    }
DB.save(&myStatus)

it successfully save the record in MySQL database like bellow

+----+-----------+------------------+---------------------+
| id | author_id | description      | publish_date        |
+----+-----------+------------------+---------------------+
|  1 |         1 | I got stuck here | 2013-01-22 23:59:59 |
+----+-----------+------------------+---------------------+

when I try to retrieve the record from MySQL database, like bellow

 var allStatus []Status
 DB.Find(&allStatus)

I gives me following error

sql: Scan error on column index 3: unsupported driver -> Scan pair: []uint8 -> *time.Time
@jinzhu
Copy link
Member

jinzhu commented Jan 25, 2014

Did you connect mysql with parseTime option?

db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")

@jinzhu jinzhu closed this as completed Jan 25, 2014
@souravray
Copy link
Author

thanks @jinzhu
I completely missed the 'parseTime' part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants