sql包的“导入错误数据库/ sql”。 我想在控制器上使用connect方法。 我认为需要安装sql程序包。
controllers/gorm.go
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/revel/revel"
"myapp/app/models"
"log"
)
添加数据库/ sql,然后尝试导入。 但是发生了错误。
错误
Revel engine is NOT listening on.. localhost:58929
/Users/toshi/gocode/src/myapp/app/controllers/gorm.go
ERROR 16:10:50 watcher.go:270: Build detected an error
error="Go Compilation Error (in app/controllers/gorm.go:4): imported and not used: \"database/sql\""
/Users/toshi/gocode/src/myapp/app/controllers/gorm.go
ERROR 16:11:49 watcher.go:270: Build detected an error
error="Go Compilation Error (in app/controllers/gorm.go:4): imported and not used: \"database/sql\""
应用路径 / Users / toshi / gocode / src / myapp
sql-driver路径 /Users/toshi/gocode/src/github.com/go-sql-driver/mysql
http://rabbitfoot141.hatenablog.com/entry/2019/03/05/000551 (参考)