init.go 511 B

1234567891011121314151617181920212223242526
  1. package models
  2. import (
  3. db "ERP_storage/initialize"
  4. "ERP_storage/models/ContractReview"
  5. _ "github.com/go-sql-driver/mysql"
  6. "log"
  7. )
  8. func init() {
  9. AutoMigrateDB()
  10. }
  11. func AutoMigrateDB() {
  12. //自动迁移模式
  13. err := db.DB.Set("gorm:table_options", "charset=utf8mb4").
  14. AutoMigrate(
  15. &ContractReview.ServiceType{},
  16. &ContractReview.ServiceItem{},
  17. &ContractReview.ContractReview{},
  18. &ContractReview.ContractReviewServiceItem{},
  19. )
  20. if err != nil {
  21. log.Fatalf("migrate db fail: %v", err)
  22. }
  23. }