转到GORM数据库自动迁移
I use Go-GORM to connect to a cockrouch DB cluster. I wrote a helper function to handle the connection and auto migrate part. Everything works fine, except when I want to auto migrate more than 1 model.
err = helperdb.HandleMigrate(db, models.Resource{}, models.Right{})
if err != nil {
helperlog.Log("Clavem", "HandleMigrate", "Error migrating resource:"+err.Error())
return
}
This is the helper function:
// HandleMigrate ...
func HandleMigrate(db *gorm.DB, models ...interface{}) error {
// this need to be checked
err := db.AutoMigrate(models).Error
if err != nil {
fmt.Println("Error HandleMigrate:" + err.Error())
return err
}
return nil
}
I get the following error:
pq: empty table name: "\"\""
When I call gorm.DB.AutoMigrate(&models.Resurce{}, models.Right{})
directly I get no error.
I realise that I do not need a helper function, but I would like to know why the helper functions does not work, especially since it is my first time working my variadic functions.
Thanks :)
douzhang8840
2017/10/09 20:01- variadic-functions
- 点赞
- 收藏
- 回答
3个回复
