在尝试使用戈尔普进行选择时,我收到了以下错误:
No table found for type: Post下面是我的代码:
type Post struct {
Id int64 `db:"post_id"`
CreatedAt int64 `db:"created_at"`
UpdatedAt int64 `db:"updated"`
Title string `db:"title"`
}
var list []*Post
_, err := dbMapper.Select(&list, "SELECT * FROM posts")
if (err != nil) {
fmt.Fprintf(writer, "%s", err)
return
}
for _, item := range list {
fmt.Fprintf(writer, "%s\n", item.Title)
}我把桌子加成这样:
dbMapper.AddTableWithName(Post{}, "posts").SetKeys(true, "Id")发布于 2014-05-25 12:19:31
你好像没做错什么。我使用postgres驱动程序在本地运行您的示例(您没有指定使用的是哪个驱动程序),它运行得很好--我猜这里缺少一些信息。要确保的事情:
dbMapper.AddTableWithName(Post{}, "posts")。您所引用的错误通常在未调用AddTableWithName时返回。sql.Open("postgres", "user=postgres dbname=test")连接到正确的数据库dbMapper := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}} (在Postgres的例子中)除此之外,我认为我们需要更多的信息才能找到这一条的真相。
https://stackoverflow.com/questions/18969242
复制相似问题