'deleted' field is not included in 'insert' #929

Closed
opened 2018-05-04 10:36:42 +00:00 by localvar · 0 comments
localvar commented 2018-05-04 10:36:42 +00:00 (Migrated from github.com)
type Foo struct {
        ID        uint64    `xorm:"'ID' pk autoincr"`
        DeletedAt time.Time `xorm:"'DELETED_AT' deleted notnull"`
}

func main() {
        db, e := xorm.NewEngine("mysql", "")
        if e != nil {
                fmt.Println(1, e.Error())
                return
        }   

        e = db.Sync2(&Foo{})
        if e != nil {
                fmt.Println(2, e.Error())
                return
        }   

        _, e = db.Insert(&Foo{})
        if e != nil {
                fmt.Println(3, e.Error())
                return
        }   

        fmt.Println("done")
}

failed with error:

3 Error 1364: Field 'DELETED_AT' doesn't have a default value

and field deleted_at are not included in the generated SQL statement.

Go: go1.10.1 linux/amd64
MySQL: 5.7.17-log
XORM: 0.6.6

seems MySQL 5.6 behave differently with MySQL 5.7 in handling default values, so this issue cannot be detected under MySQL 5.6.

```go type Foo struct { ID uint64 `xorm:"'ID' pk autoincr"` DeletedAt time.Time `xorm:"'DELETED_AT' deleted notnull"` } func main() { db, e := xorm.NewEngine("mysql", "") if e != nil { fmt.Println(1, e.Error()) return } e = db.Sync2(&Foo{}) if e != nil { fmt.Println(2, e.Error()) return } _, e = db.Insert(&Foo{}) if e != nil { fmt.Println(3, e.Error()) return } fmt.Println("done") } ``` failed with error: > 3 Error 1364: Field 'DELETED_AT' doesn't have a default value and field `deleted_at` are not included in the generated SQL statement. Go: go1.10.1 linux/amd64 MySQL: 5.7.17-log XORM: 0.6.6 seems MySQL 5.6 behave differently with MySQL 5.7 in handling default values, so this issue cannot be detected under MySQL 5.6.
lunny added this to the 1.1.1 milestone 2020-03-04 02:24:24 +00:00
lunny referenced this issue from a commit 2021-06-09 02:37:44 +00:00
lunny referenced this issue from a commit 2021-06-09 12:35:59 +00:00
lunny referenced this issue from a commit 2021-06-10 15:35:19 +00:00
lunny referenced this issue from a commit 2021-06-12 02:50:40 +00:00
lunny referenced this issue from a commit 2021-06-12 07:04:48 +00:00
lunny referenced this issue from a commit 2021-06-12 08:17:44 +00:00
lunny closed this issue 2021-07-03 12:26:50 +00:00
lunny referenced this issue from a commit 2021-07-03 12:26:50 +00:00
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#929
No description provided.