Gorm sets foreign key constraints

two tables, one is category, and the other is product, defined as follows:

type Product struct {
    ProductId  uint32 `gorm:"primary_key;type:int(11) unsigned auto_increment;"`
    Category Category `gorm:"ForeignKey:CateIDRef;"`  //category
    CateIDRef uint16 `gorm:"type:mediumint(11) unsigned not null;"`
    //CateTitle string `gorm:"type:varchar(30);not null;"`
    //Title string `gorm:"type:varchar(30)  not null;"`
    Summary string `gorm:"type:varchar(255)  not null;"`
    Num  uint32  `gorm:"type:int unsigned  not null; default:0;"`
    Price float64 `gorm:"type:decimal(10,2) unsigned not null;"`
    Pics string        `gorm:"type:varchar(500); default: "";"`
    CreateTime time.Time `gorm:"type:timestamp not null;default:current_timestamp;"`
    ModifyTime time.Time `gorm:"type:timestamp on update current_timestamp;omitempty;default:current_timestamp;"`
}

type Category struct {
    CateID uint16  `gorm:"primary_key;type:mediumint(11) not null unsigned auto_increment;"`
    ParentID uint16  `gorm:"type:mediumint(11) unsigned;not null;"`
    Title string `gorm:"type:varchar(30);not null;unique"`
    CreateTime time.Time `gorm:"type:timestamp;not null;default:current_timestamp;"`
    ModifyTime time.Time `gorm:"type:timestamp;not null on update current_timestamp;default:current_timestamp;"`
    Level uint16 `gorm:"-"`
}

but the creation of the foreign key is not successful. I don"t know the specific reason.

Jan.29,2022

db.Model(&Product{}).AddForeignKey()

in addition, these two tables do not need to set the primary foreign key association

Menu