Description
Here's my model
type SalesOrderItems struct {
ID uint `json:"id" gorm:"primaryKey"`
ItemId uint `json:"itemId" gorm:"not null;uniqueIndex:unique_soi;"`
OrderId uint `json:"orderId" gorm:"not null;index:combi_soi_order_license_idx;"`
LicenseId string `json:"licenseId" gorm:"not null;index:combi_soi_order_license_idx;uniqueIndex:unique_soi;"`
ProductId uint `json:"productId;" gorm:"not null;"`
Quantity float32 `json:"quantity" gorm:"scale:2;not null"`
NetPrice float32 `json:"netPrice" gorm:"scale:2;not null"`
Discount float32 `json:"discount" gorm:"scale:2;default:0"`
BaseDiscount float32 `json:"baseDiscount" gorm:"scale:2;default:0"`
PurchasePrice float32 `json:"purchasePrice" gorm:"scale:2;default:0"`
Tax float32 `json:"tax" gorm:"scale:4;not null;"`
CreatedAt time.Time `json:"createdAt" gorm:"not null;"`
UpdatedAt time.Time `json:"updatedAt" gorm:"not null;"`
}
When I run the migration during start up db.DB.AutoMigrate(models...) where &SalesOrderItems is an element of models gorm always executes a ALTER TABLE command on the discount column and tries to set it to 0.0000.
- the default value is already set
- the table is enormous and that command shuts down the whole DB ... as a workaround I had to exclude this table from the auto migration
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: saeidee
Please create a playground pull request since it is not reproducible with the details you provided, also you mentioned the default value is already set, what is it? Is it (0.000000) or (0.00000) if it is
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: marius-xentral
according to the screenshot the default is set to 0.000000
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: saeidee
It could be related to your database/table setup for the floating points(I am guessing you are using MySQL link) which is different for the float32 for Golang's type (it is 6 digits floating point like this: 0.000000).
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: marius-xentral
no I am actually using gorm.io/driver/postgres
Comment From: marius-xentral
@saeidee that sounds like there is a problem within this section here
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: saeidee
Could you please create a PR with steps to reproduce it in https://github.com/go-gorm/playground?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: marius-xentral
I upgraded the repo from go1.19 to go1.20 and updated gorm. the issue seems to be resolved as far as I can tell for now.