GORM Playground Link

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

Description

I need to create record in DB with false (bool), but when I have field with default field tag set to 1, it set it to 1 instead of 0

Comment From: a631807682

Use sql.NullBool

- Test bool `gorm:"default:1"`
+ Test sql.NullBool `gorm:"default:1"`

Comment From: janvrska

Sorry, but it' is'nt clear to me, why I can't use simple bool type from go types? Is there some problem in the library, which couldn't be easily fixed or is there some general "problem" which I don't understand? I'd like to know more than just use this. Because I use it like this on a project in many places in code and changing it, won't be easy. Thank you for your explanation.

Comment From: a631807682

If a value is zero, there is no way to tell whether it is a default value or a user-specified value. You can also use *bool to tell us it is specified value

Comment From: OscBacon

Hey, on a similar note, it seems that when the value is 0 for an int64 field, GORM just removes the field from the insert (it runs an INSERT INTO with all fields except that one). It looks like this is pointing to a bigger issue with default values. This is particularly an issue for me because said field is my primary key

Comment From: OscBacon

Ok well if it can help anyone, if you're trying to insert a 0 value, you need to set the field to a pointer-to-value (int64 -> *int64 in my case). By default, empty values like 0 for numbers are removed by Go