GORM Playground Link

https://github.com/go-gorm/playground/pull/713

Description

type Sample struct { ID string ``gorm:"size:128;default:(uuid())" json:"id"`` Status string ``gorm:"size:256; default:''; not null" json:"status"`` }

This is a table in which string field gets autopopulated. Either by any trigger, or in this case by the uuid function invoked on default.

w := Sample{Status: "12345"} err = DB.Create(&w).Error

Now I check w.ID -> instead of containing newly created UUID, its contains empty string .

If ID is int (autoincrement), then this works. But if ID is string, then it fails.

DB.Create() should be able to get the ID column (independent of its type being int or string)

Comment From: javiersrf

Hi! I believe the erros is not related to missing ID on return. Have you tried this on ID? Note: I believe that you will need to test using only postgresql and than add uuid extension CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

ID     uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4()" json:"id"`

Comment From: shedyfreak

Can you please specifiy which database you're using ?