go-gorm / gen

Gen: Friendly & Safer GORM powered by Code Generation
https://gorm.io/gen/
MIT License
2.25k stars 294 forks source link

If there is a unique index in the generated unit test, an error will be reported. #1148

Closed eleztian closed 2 months ago

eleztian commented 5 months ago

GORM Playground Link

https://github.com/go-gorm/playground/pull/1

Description

If there is a unique index in the generated unit test, an error will be reported.

func Test_tblUserQuery(t *testing.T) {
.....
    err = _do.CreateInBatches([]*model.TblUser{{}, {}}, 10)
    if err != nil {
        t.Error("create item in table <tbl_user> fail:", err)
    }
}
tbl_user.gen_test.go:57: create item in table <tbl_user> fail: UNIQUE constraint failed: tbl_user.ns, tbl_user.identity_id, tbl_user.name
EZ4BRUCE commented 4 months ago

same problem

qqxhb commented 4 months ago

The generated unit test is just a template and can be modified by yourself. Just don't generate a unit test next time it is generated.