sqlite3 创建记录,id为0时,插入错误 #2117

Open
opened 2022-03-02 09:31:15 +00:00 by niaiwomattt · 1 comment

sqlite3 创建记录,id为0时,插入错误
sqlite3 时创建记录 id 为 0,插入记录永远更新 id 为 0 那个记录,不会插入新记录

type Task struct {
	Id int  			  `json:"id"`
	Name string           `json:"name"` // 任务名称
	Num int               `json:"num"`// 任务序号
	Parent int            `json:"parent"`// 父级任务
	Leaf   int            `json:"leaf"`// 是否是叶子任务(没有子级的任务)
	Status int            `json:"status"`// 任务状态
	StartTime time.Time   `json:"start_time"` // 任务开始时间
	EndTime time.Time     `json:"end_time"` // 任务结束时间
	DeadLine time.Time    `json:"dead_line"` // 任务截止时间
	PauseTime time.Time   `json:"pause_time"` // 任务暂停时的时间
	UseTime time.Duration `json:"use_time"` // 执行任务所用时长
}
line, err := engine.Insert(t)

只有使用 Omit 忽略 id 字段才能插入

line, err := engine.Omit("id").Insert(t)
sqlite3 创建记录,id为0时,插入错误 sqlite3 时创建记录 id 为 0,插入记录永远更新 id 为 0 那个记录,不会插入新记录 ```go type Task struct { Id int `json:"id"` Name string `json:"name"` // 任务名称 Num int `json:"num"`// 任务序号 Parent int `json:"parent"`// 父级任务 Leaf int `json:"leaf"`// 是否是叶子任务(没有子级的任务) Status int `json:"status"`// 任务状态 StartTime time.Time `json:"start_time"` // 任务开始时间 EndTime time.Time `json:"end_time"` // 任务结束时间 DeadLine time.Time `json:"dead_line"` // 任务截止时间 PauseTime time.Time `json:"pause_time"` // 任务暂停时的时间 UseTime time.Duration `json:"use_time"` // 执行任务所用时长 } line, err := engine.Insert(t) ``` 只有使用 Omit 忽略 id 字段才能插入 ```go line, err := engine.Omit("id").Insert(t) ```

如果你的表结构和我猜的一样的话,tag 里加上 xorm:"autoincr" 就行了。

如果你的表结构和我猜的一样的话,tag 里加上 `xorm:"autoincr"` 就行了。
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#2117
No description provided.