From 35e94c8abd3767eb44620cdf7246ba04f9d9252c Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:44:12 +0100 Subject: [PATCH] [bugfix] Fix `length for type varchar must be at least 1` on Postgres (#3885) --- internal/db/bundb/migrations/util.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/db/bundb/migrations/util.go b/internal/db/bundb/migrations/util.go index 6ffcdd09d..b8a60417d 100644 --- a/internal/db/bundb/migrations/util.go +++ b/internal/db/bundb/migrations/util.go @@ -253,9 +253,14 @@ func getBunColumnDef(db bun.IDB, rtype reflect.Type, fieldName string) (string, } else { buf = append(buf, sqltype.VarChar...) } - buf = append(buf, "("...) - buf = strconv.AppendInt(buf, int64(d.DefaultVarcharLen()), 10) - buf = append(buf, ")"...) + + // Only specify varchar length for dialects + // where specifying VARCHAR length is mandatory. + if dvl := d.DefaultVarcharLen(); dvl != 0 { + buf = append(buf, "("...) + buf = strconv.AppendInt(buf, int64(dvl), 10) + buf = append(buf, ")"...) + } } // Append not null definition if field requires.