在使用beego时遇到 need a primary key field
请问这个问题要怎么解决呢?我尝试加了
orm:"column(uid);pk"
,都还是没办法
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)
type account struct {
Id int orm:"pk;column(uid);"
username string orm:"unique;size(20);"
password string orm:"size(20)"
email string orm:"size(50)"
}
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:@/finan?charset=utf8")
orm.RegisterModel(new(account))
}
func Reg() {
o := orm.NewOrm()
var Maccount account
Maccount.username = "slene"
Maccount.password = "test"
Maccount.email = "[email protected]"
id, err := o.Insert(&Maccount)
if err == nil {
fmt.Println(id)
}
}
野原新之助
10 years, 3 months ago