golang在postgresql中找不到现有表
我正在通过教程学习使用postgresql的golang中的数据库 虽然数据库存在,但程序会给出以下输出:golang在postgresql中找不到现有表,postgresql,go,Postgresql,Go,我正在通过教程学习使用postgresql的golang中的数据库 虽然数据库存在,但程序会给出以下输出: go run dbase.go 2017/01/02 20:43:07 pq: database "bookstore" does not exist 这是psql输出: deneme=# \l List of databases Name | Owner | Encoding | Collate | Ctyp
go run dbase.go
2017/01/02 20:43:07 pq: database "bookstore" does not exist
这是psql输出:
deneme=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
bookstore | postgres | UTF8 | C | C |
deneme | postgres | UTF8 | C | C |
这是go代码的相关部分:
const (
DB_USER = "postgres"
DB_PASSWORD = "root"
DB_NAME = "bookstore"
)
func main() {
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
if err != nil {
log.Fatal(err)
}
将连接代码更改为该值也会产生相同的输出:
db, err := sql.Open("postgres", "postgres://postgres:root@localhost/bookstore?sslmode=disable")
谢谢, 您是否正在运行localhost?数据库和go在同一台笔记本电脑上运行,如果您问这个问题的话。如果“running localhost”是一个关于postgres的配置术语,不,我没有做任何调整。刚刚安装了postgresql.check,以确保您没有安装多个pg Hanks,这解决了问题。