2018/01/08 19:03:47 SUCCESS ▶ 0041 Built Successfully!
2018/01/08 19:03:47 INFO ▶ 0042 Restarting 'bee-go-myBlog'...
2018/01/08 19:03:47 SUCCESS ▶ 0043 './bee-go-myBlog' is running...
[ORM]2018/01/08 19:03:47 register db `default`, sql: unknown driver "postgres" (forgotten import?)
2018/01/08 19:03:47 [I] [asm_amd64.s:2337] http server Running on http://:8080
尼玛,链接不到数据库(我不知道在哪连)!
恩!现在知道了!
func init() {
orm.RegisterDriver("postgres", orm.DRPostgres)
orm.RegisterDataBase("default", "postgres", "postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable")
}
按照上面这个,然后报错!
以为单词写错,左看右看,还是正常!
最后发现!
他喵的,包没引入!
package main
import (
_ "bee-go-myBlog/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
_"github.com/lib/pq"
)
func init() {
orm.RegisterDriver("postgres", orm.DRPostgres)
orm.RegisterDataBase("default", "postgres", "postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable")
}
func main() {
logs.SetLogger(logs.AdapterFile, `{"filename":"/Users/zhu/go/src/bee-go-myBlog/test.log"}`)
beego.Run()
}
ok 不报错了
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习