I'm encountering unexpected behavior with GORM (v1.30.1) when inserting a record that includes a boolean field with default:true. Even when I explicitly send "is_active": false in the request JSON, GORM still inserts it as true in the database.
my model
type ProductCategory struct {
gorm.Model
Name string
json:"name" gorm:"unique;not null"NameTr string
json:"name_tr" gorm:"size:100"Description string
json:"description" gorm:"type:text"Slug string
json:"slug" gorm:"uniqueIndex;size:100;not null"SortOrder int
json:"sort_order" gorm:"default:0"IsActive bool
json:"is_active" gorm:"default:true"}
`2025/07/30 10:28:11 main.go:419: Starting server on http://localhost:8070 ... 2025/07/30 10:28:14 misc.go:86: Key 'root' is object with 6 fields 2025/07/30 10:28:14 misc.go:64: Key 'slug' is string: altin1 2025/07/30 10:28:14 misc.go:77: Key 'sort_order' is float64: 1.000000 2025/07/30 10:28:14 misc.go:79: Key 'is_active' is bool: false 2025/07/30 10:28:14 misc.go:64: Key 'name' is string: Altın1 2025/07/30 10:28:14 misc.go:64: Key 'name_tr' is string: Altın1 2025/07/30 10:28:14 misc.go:64: Key 'description' is string: Altın ürün kategorisi 2025/07/30 10:28:14 category.go:97: Parsed category.IsActive : false
2025/07/30 10:28:14 /Users/adam/zerduz/kuyum-go/market/handlers/category.go:99
[4.334ms] [rows:1] INSERT INTO product_categories
(created_at
,updated_at
,deleted_at
,name
,name_tr
,description
,slug
,sort_order
,is_active
) VALUES ('2025-07-30 10:28:14.382','2025-07-30 10:28:14.382',NULL,'Altın1','Altın1','Altın ürün kategorisi','altin1',1,true)`
Environment:
GORM version: v1.30.1
Go version: go1.24.5
Database: (MySQL 8.4)
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: Fuzzyma
This is an issue I run into today. Using "default: true" on any boolean field pretty much makes it always true even when specifically setting it to false:
package main
import (
"log"
"syscall"
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func main() {
connectionString := "host=localhost user=postgres password=yourpassword dbname=treed port=5432 sslmode=disable TimeZone=Europe/Berlin"
db, _ := gorm.Open(postgres.Open(connectionString), &gorm.Config{})
type Tree struct {
ID uint `json:"id"`
Exists bool `json:"exists" gorm:"default:true"`
Height float64 `json:"height" gorm:"type:FLOAT"`
}
tree := Tree{
Exists: false,
Height: 10.0,
}
db.Create(&tree)
var debugCount struct {
ExistsTrue int64 `json:"exists_true"`
ExistsFalse int64 `json:"exists_false"`
}
db.Model(&Tree{}).Where("exists = ?", true).Count(&debugCount.ExistsTrue)
db.Model(&Tree{}).Where("exists = ?", false).Count(&debugCount.ExistsFalse)
fmt.Printf("DEBUG: After insert - has %d trees with exists=true, %d with exists=false\n",
debugCount.ExistsTrue, debugCount.ExistsFalse)
}
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: Fuzzyma
Reproduction:
https://github.com/go-gorm/playground/pull/824
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨