Hi! i have an issue with the generated columns value with GORM.
My struct
type Product struct {
gorm.Model
Name string `json:"name" gorm:"not null"`
Quantity uint `json:"quantity" gorm:"not null"`
Price float64 `json:"price" gorm:"not null"`
Gain float64 `json:"gain" gorm:"not null"`
Total float64 `json:"total" gorm:"->;type:GENERATED ALWAYS AS (quantity*price);"` // generated total price
TotalGain float64 `json:"total_gain" gorm:"->;type:GENERATED ALWAYS AS (quantity*gain);"` // generated total gain
ProcessID uint // one-to-many
}
auto migration
err = database.AutoMigrate(&models.Process{}, &models.Product{})
if err != nil {
return err
}
This is the error
cannot INSERT into generated column "total"
[0.021ms] [rows:0] INSERT INTO `products__temp`(`id`,`created_at`,`updated_at`,`deleted_at`,`name`,`quantity`,`price`,`gain`,`total`,`total_gain`,`process_id`) SELECT `id`,`created_at`,`updated_at`,`deleted_at`,`name`,`quantity`,`price`,`gain`,`total`,`total_gain`,`process_id` FROM `products`
It seems like GORM has created a temporary table "products__temp" a clone of "products" table. So as we can know we cannot insert or edit the generated columns!
Note: i'm working wih SQLite
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: 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: 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 ✨