go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
89 stars 678 forks source link

automigrate with many2many is easy to make mistakes #615

Open yudidi opened 1 year ago

yudidi commented 1 year ago

Explain your user case and expected results

err := DB.AutoMigrate(&User{}, &UserFriend{}) 当开发者对gorm的AutoMigrate和many2many标签了解不深入时,容易像我上面那样使用AutoMigrate。 当gorm使用默认配置时(IgnoreRelationshipsWhenMigrating=false),开发者可能容易忽略many2many会创建关联表,同时还会给表创建唯一的联合索引。 这样关系表就无法新增一个id主键索引了。 你觉得应该如何改善这个问题?