陶醉于Gorm“未定义:页面”

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?

You forgot to add the package identifier of your model: as your model struct is defined in another package, it's name (locally to the controllers package) should be models.Page.

If you really want to get rid of the package identifier and do like it was locally defined, I think that you can also import your models package locally by assigning it to the . identifier. Example:

import (
    . "myapp/app/models"
)