mysql timestamp error with time.Now() golang

Viewed 6360

How to save time.Now() in mysql table, column name as created_at timestamp null.

I am getting error :

Error:Error 1292: Incorrect datetime value: '2017-08-05 19:06:14.190 +0000' for column 'created_at' at row 1

More Information as asked :- ( I am using fragmenta cms, so all reference code with their line number is given below )

Table schema :-

mysql> describe users;
+----------------------+--------------+------+-----+---------+----------------+
| Field                | Type         | Null | Key | Default | Extra          |
+----------------------+--------------+------+-----+---------+----------------+
| id                   | int(11)      | NO   | PRI | NULL    | auto_increment |
| created_at           | timestamp    | YES  |     | NULL    |                |
| updated_at           | timestamp    | YES  |     | NULL    |                |
| status               | int(11)      | YES  |     | NULL    |                |
| role                 | int(11)      | YES  |     | NULL    |                |
| name                 | varchar(250) | YES  |     | NULL    |                |
| email                | varchar(250) | YES  |     | NULL    |                |
| title                | varchar(250) | YES  |     | NULL    |                |
| summary              | text         | YES  |     | NULL    |                |
| text                 | text         | YES  |     | NULL    |                |
| image_id             | int(11)      | YES  |     | NULL    |                |
| password_hash        | varchar(250) | YES  |     | NULL    |                |
| password_reset_token | text         | YES  |     | NULL    |                |
| password_reset_at    | timestamp    | YES  |     | NULL    |                |
+----------------------+--------------+------+-----+---------+----------------+

Code that is running it to save :-

At line no. 62 here ( https://github.com/fragmenta/fragmenta-cms/blob/master/src/pages/actions/setup.go#L62 )

It calls code user := users.New()

in Line no. 51 at file here ( https://github.com/fragmenta/fragmenta-cms/blob/master/src/users/query.go#L51 )

New() function is setup.

Which is like :-

func New() *User {
    user := &User{}
    user.CreatedAt = time.Now()
    user.UpdatedAt = time.Now()
    user.TableName = TableName
    user.KeyName = KeyName
    user.Status = status.Draft
    return user
}

and their connecting / mysql opening pattern is located here ( https://github.com/fragmenta/query/blob/master/adapters/database_mysql.go#L23 ) .

2 Answers
Related