From 751028549d18c9c3a3c99d27dad057a196b84ce0 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 28 Jul 2023 17:08:11 +0800 Subject: [PATCH] Prevent primary key update on migration (#26192) (#26199) Backport #26192 by @KN4CK3R Fixes #25918 The migration fails on MSSQL because xorm tries to update the primary key column. xorm prevents this if the column is marked as auto increment: https://gitea.com/xorm/xorm/src/commit/c622cdaf893fbfe3f40a6b79f6bc17ee10f53865/internal/statements/update.go#L38-L40 I think it would be better if xorm would check for primary key columns here because updating such columns is bad practice. It looks like if that auto increment check should do the same. fyi @lunny Co-authored-by: KN4CK3R (cherry picked from commit ecfbcced46d7a4489fcb94cca138110434423b82) --- models/migrations/v1_20/v250.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_20/v250.go b/models/migrations/v1_20/v250.go index e05646e5c6..a09957b291 100644 --- a/models/migrations/v1_20/v250.go +++ b/models/migrations/v1_20/v250.go @@ -20,7 +20,7 @@ func ChangeContainerMetadataMultiArch(x *xorm.Engine) error { } type PackageVersion struct { - ID int64 `xorm:"pk"` + ID int64 `xorm:"pk autoincr"` MetadataJSON string `xorm:"metadata_json"` }