I'm just trying to create new project with revel
, gorm
and pq
.
I have model Page
in 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
}
and gorm.go
in 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{})
}
I have the error undefined: Page
in line DB.AutoMigrate(Page{})
, but I linked my models in line _ "myapp/app/models"
. What's wrong?