Beego迁移引发错误:必须具有一个名为`default`

时间:2019-03-18 08:55:24

标签: mysql database go migration beego

我使用此命令生成一个简单的模型:

bee generate model user -fields="UserName:string,first_name:string"

然后我创建了一个新的迁移文件:

bee generate migration user -driver=mysql -fields="user_name:string,first_name:string"

生成的:

package main

import (
    "github.com/astaxie/beego/migration"
)

// DO NOT MODIFY
type User_20190318_014641 struct {
    migration.Migration
}

// DO NOT MODIFY
func init() {
    m := &User_20190318_014641{}
    m.Created = "20190318_014641"

    migration.Register("User_20190318_014641", m)
}

// Run the migrations
func (m *User_20190318_014641) Up() {
    // use m.SQL("CREATE TABLE ...") to make schema update
    m.SQL("CREATE TABLE user(`id` int(11) NOT NULL AUTO_INCREMENT,`user_name` varchar(128) NOT NULL,`first_name` varchar(128) NOT NULL,PRIMARY KEY (`id`))")
}

// Reverse the migrations
func (m *User_20190318_014641) Down() {
    // use m.SQL("DROP TABLE ...") to reverse schema update
    m.SQL("DROP TABLE `user`")
}

这一切都很好,但是当我尝试运行迁移时:

bee migrate -conn="root:@tcp(127.0.0.1:3306)/my_db_name?charset=utf8" -driver='mysql'

但是,我不断收到错误消息:

2019/03/18 22:23:09 INFO     ▶ 0001 Using 'mysql' as 'driver'
2019/03/18 22:23:09 INFO     ▶ 0002 Using 'root:@tcp(127.0.0.1:3306)/my_db_name' as 'conn'
2019/03/18 22:23:09 INFO     ▶ 0003 Using '/Users/me/go/src/code-go/database/migrations' as 'dir'
2019/03/18 22:23:09 INFO     ▶ 0004 Running all outstanding migrations
2019/03/18 22:23:10 INFO     ▶ 0005 |> 2019/03/18 22:23:10.804 [I]  start upgrade User_20190318_211625
2019/03/18 22:23:10 INFO     ▶ 0006 |> must have one register DataBase alias named `default`
2019/03/18 22:23:10 ERROR    ▶ 0007 Could not run migration binary: exit status 2

有什么想法吗?

0 个答案:

没有答案