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

Closed
opened 4 years ago by localvar · 0 comments
localvar commented 4 years ago (Migrated from github.com)
Owner
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 2 years ago
lunny referenced this issue from a commit 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny closed this issue 5 months ago
lunny referenced this issue from a commit 5 months ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.