GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
在结构体中添加某个主键,使用db.Save方法修改时,第一次成功创建数据,第二次的时候将created_at字段数据改为了'0000-00-00 00:00:00'
type TwelveHoursActivityMemberSetting struct {
MemberUuid string `gorm:"primaryKey" json:"member_uuid"`
TwelveHoursActivityId int `json:"twelve_hours_activity_id"`
Numbers int `json:"numbers"`
TotalQuantity int `json:"total_quantity"`
IsMyResolve int `json:"is_my_resolve"`
IsCalendar int `json:"is_calendar"`
Weekly datatypes.JSON `json:"weekly"`
ReminderTime datatypes.JSON `json:"reminder_time"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
twelveHoursActivityMemberSettingMap := models.TwelveHoursActivityMemberSetting{
MemberUuid: authUser.Uuid,
TwelveHoursActivityId: twelveHoursActivity.Id,
Numbers: data.Numbers,
IsMyResolve: 0,
IsCalendar: data.IsCalendar,
Weekly: weekly,
ReminderTime: reminderTime,
}
db = common.Db.Save(&twelveHoursActivityMemberSettingMap)
后面两个时间分别是,created_at和updated_at 第一次执行结果
07af18e1-0987-4d6b-9679-c1a3ec6c3eb3 1 8 0 0 0 ["1", "2"] ["07:45", "20:00"] 2021-06-03 16:41:33 2021-06-03 16:41:33
第二次执行结果
07af18e1-0987-4d6b-9679-c1a3ec6c3eb3 1 8 0 0 0 ["1", "2"] ["07:45", "20:00"] 0000-00-00 00:00:00 2021-06-03 16:43:35
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: tommiyxu
@XuruiPro created_at更新变0 这个怎么处理的?翻了半天issues都没找到 :-(
Comment From: tc7326
Model {
CreatedAt time.Time gorm:"<-:create" // Allow reading and creation
}