Your Question

I have this model:

type sqlModel struct {
    Id              string `gorm:"primaryKey"`
    ProductId       string `gorm:"type:uuid;not null;"`
    Quantity        int
    CreatedAt time.Time `gorm:"autoCreateTime:false"`
    UpdatedAt time.Time `gorm:"autoUpdateTime:false"`
}

Gorm keeps updating the fields in the database overwriting any value from the model.

For save/create I use:

if err := r.dbWrite.WithContext(ctx).Save(&sqlModel).Error; err != nil {
        return err
    }

and

if err := r.dbWrite.WithContext(ctx).Create(&sqlModel).Error; err != nil {
return err
}

I'm using: gorm.io/gorm v1.22.5

The document you expected this should be explained

https://gorm.io/docs/conventions.html#Timestamp-Tracking

Expected answer

I miss something?

Is maybe the version i'm using?

Thanks in advance

Comment From: dcorto

I finally updated from:

gorm.io/driver/mysql v1.2.3 gorm.io/gorm v1.22.5

to:

gorm.io/driver/mysql v1.5.0 gorm.io/gorm v1.25.0

And now is working as expected.

Thanks