bee migrate 报错处理

文章描述了在使用beego进行数据库迁移时遇到的两个错误:构建迁移二进制失败和临时文件删除问题。解决方法是重新拉取beego并运行迁移命令。内容包含了一个User数据表的创建和迁移脚本。
摘要由CSDN通过智能技术生成

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")
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值