From 3aec6c2cae9743c2701fc2ae35c5d03396f15386 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 4 Jun 2026 19:51:56 -0500 Subject: [PATCH] fix(migration): set issue_id default to 0 for new custom_field_value inserts The old issue_id column has NOT NULL without a default, causing inserts via the new entity_id-based API to fail. Migration now ALTERs the column to DEFAULT 0. Co-Authored-By: Claude Opus 4.6 (1M context) --- models/migrations/v1_27/v345.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_27/v345.go b/models/migrations/v1_27/v345.go index 026cc1da8d..197513fa59 100644 --- a/models/migrations/v1_27/v345.go +++ b/models/migrations/v1_27/v345.go @@ -29,6 +29,11 @@ func MigrateCustomFieldsToOrgLevel(x *xorm.Engine) error { } // Migrate existing data: copy issue_id to entity_id where entity_id is 0 - _, err := x.Exec("UPDATE custom_field_value SET entity_id = issue_id WHERE entity_id = 0 AND issue_id != 0") + if _, err := x.Exec("UPDATE custom_field_value SET entity_id = issue_id WHERE entity_id = 0 AND issue_id != 0"); err != nil { + return err + } + + // Set issue_id default to 0 so new inserts don't require it + _, err := x.Exec("ALTER TABLE custom_field_value MODIFY COLUMN issue_id bigint NOT NULL DEFAULT 0") return err } -- 2.52.0