Golang Gorm Automigrate not create filed type "time"

Viewed 64

My struct looks like:

type AdvertContent struct {
    Id          string     `gorm:"column:id;primaryKey;type:uuid;default:uuid_generate_v4()" json:"id" example:"4ff8eb91-640b-4e26-a50f-3bcd1f933d0c"`
    FromTime    *time.Time `gorm:"column:from_time;type:time;" json:"fromTime,omitempty" example:"HH:MM"`                                            
    ToTime      *time.Time `gorm:"column:to_time;type:time;" json:"toTime,omitempty" example:"HH:MM"`                                            
} //@name AdvertContent

func (this AdvertContent) TableName() string {
    return "advert_content"
}

When I use gorm.AutoMigrate, table fields from_time and to_time created with type timestampz, not time.

Gorm debug mode:

CREATE TABLE "advert_content" ("id" uuid DEFAULT uuid_generate_v4(),"from_time" timestamptz,"to_time" timestamptz)

How can I create table with time type fields?

1 Answers

when using specified database data type, it needs to be a full database data type, for example: MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT

You should use the database data type like this

Related