我只是想用revel
,gorm
和创建新项目pq
。我有Page
模型app/models
:
package models
import (
"time"
)
type Page struct {
Id int64
Title string `sql:"size:255"`
Context string
Url string
MetaKeys string
MetaDescr string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
}
并gorm.go
在app/controllers
:
package controllers
import (
_ "myapp/app/models"
_ "code.google.com/p/go.crypto/bcrypt"
_ "database/sql"
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
_ "github.com/revel/revel"
"github.com/revel/revel/modules/db/app"
)
var (
DB gorm.DB
)
func InitDB() {
db.Init()
var err error
DB, err = gorm.Open("postgres", "user=postgres dbname=mydb_development sslmode=disable")
if err != nil {
panic(fmt.Sprintf("Got error when connect database, the error is '%v'", err))
}
DB.LogMode(true)
DB.AutoMigrate(Page{})
}
我有错误undefined: Page
,DB.AutoMigrate(Page{})
但我将我的模型链接在一起_ "myapp/app/models"
。怎么了?