Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以看到我们这样自动迁移的文档, db.AutoMigrate(&model.TheTodo{})
db.AutoMigrate(&model.TheTodo{})
如果我们有很多倍数模型怎么办?db.AutoMigrate(&model.TheTodo{}, &model.TheBlog{}, &model.Employee{}, and many more...... )
db.AutoMigrate(&model.TheTodo{}, &model.TheBlog{}, &model.Employee{}, and many more...... )
如果我们这样放,gorm 会创建那个表吗?这有什么方法可以让 AutoMigrate 内部变得简短吗?
db.AutoMigrate(allmodels)
有可能吗?
一种选择是将结构嵌套在AutoMigrate函数内:
AutoMigrate
db.AutoMigrate( &User{}, &Product{}, &Order{}, )
或者,如果您想让内部“变短”,您可以这样做:
var models = []interface{}{&User{}, &Product{}, &Order{}} db.Automigrate(models...)