bee migrate -driver="mysql" -conn="root:root@tcp(127.0.0.1:3306)/beego"
报错解决:
错误1:Could not build migration binary: exit status 1
错误2: Could not remove temporary file: remove m.exe: The system cannot find the file specified
报错截图:
解决办法:重新拉取 beego
go get -u github.com/beego/bee
重新执行:bee migrate -driver="mysql" -conn="root:root@tcp(127.0.0.1:3306)/beego"
数据表文件:
package main
import (
"github.com/beego/beego/v2/client/orm/migration"
)
// DO NOT MODIFY
type User_20240114_105845 struct {
migration.Migration
}
// DO NOT MODIFY
func init() {
m := &User_20240114_105845{}
m.Created = "20240114_105845"
err := migration.Register("User_20240114_105845", m)
if err != nil {
return
}
}
// Run the migrations
func (m *User_20240114_105845) Up() {
// use m.SQL("CREATE TABLE ...") to make schema update
m.CreateTable("user", "innodb", "utf8")
m.PriCol("id").SetAuto(true).SetDataType("int").SetUnsigned(true)
m.NewCol("username").SetDataType("varchar(255)")
m.NewCol("password").SetDataType("varchar(255)")
m.NewCol("email").SetDataType("varchar(255)").SetNullable(true)
m.NewCol("login_count").SetDataType("int").SetUnsigned(true)
m.NewCol("last_time").SetDataType("datetime")
m.NewCol("last_ip").SetDataType("varchar(255)").SetNullable(true)
m.NewCol("state").SetDataType("smallint(2)")
m.NewCol("created_at").SetDataType("datetime")
m.NewCol("updated_at").SetDataType("datetime")
m.SQL(m.GetSQL())
}
// Reverse the migrations
func (m *User_20240114_105845) Down() {
// use m.SQL("DROP TABLE ...") to reverse schema update
//m.SQL("DROP TABLE IF EXISTS user")
}