From b051fb49017b32d1c62a5cb3dba880d9e10d751a Mon Sep 17 00:00:00 2001 From: barnettZQG Date: Sat, 28 Apr 2018 13:00:17 +0800 Subject: [PATCH] Support primary key have the capital letter if use postgresql, eg: ``` //Model type Model struct { ID uint `gorm:"column:ID;primary_key"` CreatedAt time.Time `gorm:"column:create_time"` } ``` insert data error: ``` pq: column name "id" not found ``` --- callback_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callback_create.go b/callback_create.go index e7fe6f86..b8b38816 100644 --- a/callback_create.go +++ b/callback_create.go @@ -146,7 +146,7 @@ func forceReloadAfterCreateCallback(scope *Scope) { db := scope.DB().New().Table(scope.TableName()).Select(blankColumnsWithDefaultValue.([]string)) for _, field := range scope.Fields() { if field.IsPrimaryKey && !field.IsBlank { - db = db.Where(fmt.Sprintf("%v = ?", field.DBName), field.Field.Interface()) + db = db.Where(fmt.Sprintf("\"%v\" = ?", field.DBName), field.Field.Interface()) } } db.Scan(scope.Value)