Skip to content

bool field with default:true always stored as true, even when explicitly set to false in JSON #7543

@avary

Description

@avary

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)

playground link : go-gorm/playground#824

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions