1 回答

TA貢獻1777條經驗 獲得超3個贊
我不知道它是如何工作的,但我之前的代碼是這樣的:
func Connect() {
db, err := gorm.Open(postgres.Open("postgres://postgres:qwerty@localhost:5432/shop"), &gorm.Config{})
if err != nil {
panic(err)
}
db.AutoMigrate(&models.Categories{}, &models.Products{}, &models.Pagination{}, &models.Feedback{}, &models.Cart{}, &models.Jurik{}, &models.Phyz{}, &models.Order{})
DB = db
}
然后我嘗試單獨遷移Order:
func Connect() {
db, err := gorm.Open(postgres.Open("postgres://postgres:qwerty@localhost:5432/shop"), &gorm.Config{})
if err != nil {
panic(err)
}
db.AutoMigrate(&models.Categories{}, &models.Products{}, &models.Pagination{}, &models.Feedback{}, &models.Cart{}, &models.Jurik{}, &models.Phyz{})
db.AutoMigrate(&models.Order{})
DB = db
}
希望這對某人有幫助!
- 1 回答
- 0 關注
- 107 瀏覽
添加回答
舉報