Beego: Create database with migration beego

Created on 5 Dec 2017  路  1Comment  路  Source: astaxie/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

areorm kinquestion

Most helpful comment

add this code after m.PriCol

sql := m.GetSQL()
m.SQL(sql)

>All comments

add this code after m.PriCol

sql := m.GetSQL()
m.SQL(sql)
Was this page helpful?
0 / 5 - 0 ratings