this is the model
type Collection struct {
Name string `json:"name" binding:"min=1,max=20" gorm:"type:varchar(20);not null;"`
User muser.User `json:"-" binding:"-" gorm:"foreignKey:Openid;references:Openid;"`
Openid string `json:"-"`
TID int64 `json:"tid" gorm:"type:BIGINT;not null;"`
gorm.Model
UpdatedAt int
}
automigrate debug sql is:
ALTER TABLE `users` ADD CONSTRAINT `fk_collections_user` FOREIGN KEY (`openid`) REFERENCES `collections`(`openid`)
get the err:
Error 1824: Failed to open the referenced table 'collections'
I think it must be:
ALTER TABLE `collections` ADD CONSTRAINT `fk_collections_user` FOREIGN KEY (`openid`) REFERENCES `users`(`openid`)
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 2 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: KiddoV
Any update on this? I ran into the same problem. As a work around, I have to change my field name so it's not the same with each others.
Comment From: M03ED
i have same problem