mysql自增主键,在insert的时候 显示"Error 1364: Field 'id' doesn't have a default value" #1090

Open
opened 2018-09-04 06:55:10 +00:00 by knight0zh · 1 comment
knight0zh commented 2018-09-04 06:55:10 +00:00 (Migrated from github.com)

表设置的 自增主键.
结构体id为0值,
engineer.ShowSQL(true)
这部分也没问题
type A struct{
Id int json:"id" xorm:"not null pk autoincr INT(11)"
}
报错返回
这是什么原因

表设置的 自增主键. 结构体id为0值, engineer.ShowSQL(true) 这部分也没问题 type A struct{ Id int `json:"id" xorm:"not null pk autoincr INT(11)"` } 报错返回 这是什么原因
fanspace commented 2018-09-05 06:25:40 +00:00 (Migrated from github.com)

报得什么错? 加个unique 约束试试
Id int json:"id" xorm:"not null pk autoincr unique INT(11)"
有可能你的数据是重复的。
另外最外边需要加`` 反引号

报得什么错? 加个unique 约束试试 Id int `json:"id" xorm:"not null pk autoincr unique INT(11)"` 有可能你的数据是重复的。 另外最外边需要加`` 反引号
Sign in to join this conversation.
No Milestone
No Assignees
1 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#1090
No description provided.