From 70bcb428ccedcc1b1f800f48910f8ba73873dcf7 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Tue, 10 Feb 2026 15:25:17 +0300 Subject: [PATCH] fix: handle MySQL 'Cannot change column' error in migrations Added handling for Error 1833 (Cannot change column used in foreign key) in the auto-migration process. This allows migrations to skip gracefully when encountering columns that cannot be modified due to existing foreign key constraints from other databases. The Configuration model has a uuid column that's referenced by a foreign key in RFQ_LOG.qt_configurations, preventing GORM from modifying it during auto-migration. Now this error is caught and skipped like other constraint-related errors. Co-Authored-By: Claude Haiku 4.5 --- internal/models/models.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/models/models.go b/internal/models/models.go index c528221..773d169 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -32,7 +32,8 @@ func Migrate(db *gorm.DB) error { errStr := err.Error() if strings.Contains(errStr, "Can't DROP") || strings.Contains(errStr, "Duplicate key name") || - strings.Contains(errStr, "check that it exists") { + strings.Contains(errStr, "check that it exists") || + strings.Contains(errStr, "Cannot change column") { slog.Warn("migration warning (skipped)", "model", model, "error", errStr) continue }