h2. model
type PriceDaily struct {
Product string `gorm:"primaryKey"`
Date string `gorm:"primaryKey"`
Price uint64
}
h2. code
func somefn() error{
pd1 := PriceDaily{Product: "jinzhu", Date: "20220110", Price: 100}
pd2 := PriceDaily{Product: "jinzhu", Date: "20220111", Price: 10000}
err := DB.Save(&pd1).Error
if err != nil {
return err
}
err = DB.Save(&pd2).Error
if err != nil {
return err
}
}
h2. ERROR
Error 1062: Duplicate entry 'jinzhu' for key 'PRIMARY'
h2.truth
after describe table I found only the product field is PRI, the date field is MUL instead of PRI.
h2. question
am I using gorm wrong or this is a bug?
Comment From: jinzhu
tests pass for me, maybe the table is not created GORM?
FYI, GORM can't auto migrate primary fields.