Skip to content

时间字赋值为 nil 时 数据库不会更新时间字段为空 #4589

@isafer-sen

Description

@isafer-sen

Description

在使用 GoFrame v2.9.7 操作 MySQL 5.7 数据库时,当尝试将时间字段更新为 nil 时,数据库不会把时间字段更新为空而是保留老的时间不会清除,而不是真正的 NULL。这导致在业务逻辑中无法将时间字段清空。

Additional

CREATE TABLE nfc_lock_device (
    id INT PRIMARY KEY,
    device_gui_time TIMESTAMP NULL DEFAULT NULL
);

type NfcLockDeviceUpdate struct {
    DeviceGuiTime      *gtime.Time `json:"device_gui_time"      orm:"DEVICE_GUI_TIME"
}

data :=NfcLockDeviceUpdate{
    DeviceGuiTime: nil,
}
_, err = dao.NfcLockDevice.Ctx(ctx).Where(dao.NfcLockDevice.Columns().Id, req.Id).Data(data).Update

执行后,device_gui_time 字段不会被设置NULL
期望行为
1、当时间字段被显式设置为 nil 时,应该生成 SET column = NULL 的 SQL
2、提供一种明确的方式来表示字段应该被设置为 NULL
3、保持向后兼容性

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions