GORM Playground Link
https://github.com/go-gorm/playground/pull/546/files
Description
I just ran into this bug when I did some refactoring and a "Belongs To" relation ended up with a default:NULL gorm tag.
This ended up messing with the SQL generation for a Create Query.
Additionally to the playground PR I wrote a reproducer here:
Open
package main
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
)
type User struct {
OrganizationID string
Organization Organization `gorm:"default:NULL"`
}
type Organization struct {
ID string
}
func main() {
dsn := "host=localhost user=<user> password=<pass> dbname=<db> port=5432"
db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})
user := User{
OrganizationID: "b07f69f4-1dc2-45df-bb54-4d4f5e227cb4",
}
tx := db.Create(&user)
log.Println(tx.Error)
}
**stdout**
2022/11/25 21:44:14 /home/max/Dokumente/helpwave/gormissue/main.go:38 ERROR: unterminated quoted identifier at or near """ (SQLSTATE 42601)
[0.693ms] [rows:0] INSERT INTO "users" ("organization_id") VALUES ('b07f69f4-1dc2-45df-bb54-4d4f5e227cb4') RETURNING "
2022/11/25 21:44:14 ERROR: unterminated quoted identifier at or near """ (SQLSTATE 42601)