db.AutoMigrate(&Address{}, &Apply{}, &Banner{}, &Booth{}, &Category{}, &Comment{}, &Coupon{}, &Dictionary{}, &Group{}, &Img{}, &Order{}, &Product{}, &Tag{}, &Topic{}, &User{})

 

给每张表添加表注释

db.Set("gorm:table_options", "comment '用户地址表' ").AutoMigrate(&Address{})

  

像这种一个个写。

 

当然更好的方式是用循环

 

type modelAuto struct {
		Model   interface{}
		Comment string
	}

	models := []modelAuto{
		modelAuto{&Address{}, "1111"},
		modelAuto{&Apply{}, "2222"},
	}

	for _, val := range models {
		fmt.Println(val.Model)
		db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
	}

  

相关文章:

  • 2021-10-26
  • 2021-11-10
  • 2022-12-23
  • 2022-01-29
  • 2021-05-30
  • 2022-12-23
  • 2021-07-08
猜你喜欢
  • 2021-05-26
  • 2021-12-24
  • 2021-05-15
  • 2021-06-13
  • 2023-02-16
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案