The code: https://gist.github.com/ainar-g/7323528
If I use &User{} instead of User{}, or remove CreatedAt and UpdatedAt fields, it works as it should. But otherwise, it causes this:
panic: reflect: reflect.Value.Set using unaddressable value
goroutine 1 [running]:
reflect.flag.mustBeAssignable(0x192)
/usr/lib/go/src/pkg/reflect/value.go:268 +0x151
reflect.Value.Set(0x81d0c80, 0x1846a478, 0x192, 0x81d0c80, 0x1846dfe0, ...)
/usr/lib/go/src/pkg/reflect/value.go:1373 +0x29
github.com/jinzhu/gorm.(*Model).fields(0x184a06a0, 0x81d8788, 0x6, 0x18484480, 0x3, ...)
/home/ainar/go/src/github.com/jinzhu/gorm/model.go:120 +0xc2b
github.com/jinzhu/gorm.(*Do).createTable(0x184740b0, 0x81c4a20)
/home/ainar/go/src/github.com/jinzhu/gorm/do.go:689 +0x64
github.com/jinzhu/gorm.(*Chain).CreateTable(0x1846e140, 0x81c4a20, 0x1846a460, 0x1846e000)
/home/ainar/go/src/github.com/jinzhu/gorm/chain.go:237 +0x45
github.com/jinzhu/gorm.(*DB).CreateTable(0x1846d150, 0x81c4a20, 0x1846a460, 0x0)
/home/ainar/go/src/github.com/jinzhu/gorm/main.go:106 +0x7c
main.main()
/home/ainar/playground/go/db.go:36 +0x1a1
goroutine 2 [syscall]:
exit status 2
Comment From: jinzhu
Thank you for your report and nice example, I found what caused this and fixed in the master branch.
Comment From: thekidder
I am seeing this issue reoccur on v1.24.3 -- did anything regress here?