drhanjuw56233 2017-12-05 09:33
浏览 165

使用迁移beego创建数据库

I already created migration file via bee generate migration create_users_table. Then i had one file in folder database/migrations/20171205_154034_create_users_table.go This is my file :

package main

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

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

// DO NOT MODIFY
func init() {
    m := &CreateUsersTable_20171205_154034{}
    m.Created = "20171205_154034"

    migration.Register("CreateUsersTable_20171205_154034", m)
}

// Run the migrations
func (m *CreateUsersTable_20171205_154034) Up() {
    m.CreateTable("users","InnoDB","utf8")
    m.PriCol("id").SetAuto(true).SetNullable(false).SetDataType("INT(10)").SetUnsigned(true)
}

// Reverse the migrations
func (m *CreateUsersTable_20171205_154034) Down() {
    m.SQL("DROP TABLE users")
}

Finally, i run bee migrate -conn="username:password@tcp(127.0.0.1:3306)/mydb". I got Migration successful! no error. But i did not have users table in database. Whats wrong? Thank you for reading. Hope anyone help me

  • 写回答

1条回答 默认 最新

  • douzhi3667 2017-12-09 18:59
    关注

    To address your problem, you're not executing your SQL in the end.

    Add the following line to your Up():

    m.SQL(m.GetSQL())
    
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示