import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type XnAddress struct {
ID int64 `gorm:"primaryKey;column:id;type:int;not null;comment:'id'" json:"-"` // id
Address string `gorm:"column:address;type:varchar(50);default:null;" json:"address"`
}
func (m *XnAddress) TableName() string {
return "xn_address"
}
type Chat struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
UId int64 `gorm:"column:u_id"`
IsSystem int64
Content string `gorm:"type:text"`
Read int `gorm:"default:0"`
XnAddress XnAddress `gorm:"foreignkey:UId;AssociationForeignKey:ID;save_associations:false"`
}
Db.AutoMigrate(&XnAddress{})
Db.AutoMigrate(&Chat{})
output SQL:
ALTER TABLE `xn_address` MODIFY COLUMN `address` bigint DEFAULT null
I have defined the field address as a string type, and the migration table chat will change the address type Why change the type of Address? How to fix it?
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 ✨