在GoLang中运行任何SQL查询时,我会收到以下错误。请问是否有其他解决方法?
我希望以上代码没有错误,因为在我的Windows环境中可以工作,但我不想在Windows上进行开发。这一切都在我的Linux环境中,自从转移后...我遇到了这个问题。
以下是postgres用户在数据库上的权限。
pq: relation "users" does not exist
我尝试过:
检查了数据库的权限,一切都正常。
检查了凭据是否正确
直接通过psql在SQL数据库上运行INSERT语句
创建了一个极简程序以确保我的代码中没有其他问题
手动输入查询字符串中的值,而不使用参数
尝试了SELECT语句并出现了同样的问题。它只是找不到用户表。
我已经通过const变量构建了连接字符串,就像下面这样。两种方法都没有起作用。
我尝试了带端口(5432)和不带端口的情况
以下是我拥有的代码(极简应用程序输出与我的主应用程序相同的错误)
func main() {
sqlInfo := fmt.Sprintf("postgres://postgres:postgres@localhost/user_details?sslmode=disable")
db, err := sql.Open("postgres", sqlInfo)
defer db.Close()
if err != nil {
fmt.Fprintf(os.Stdout, "Connection to the database failed")
return
}
err = db.Ping()
if err != nil {
fmt.Fprintf(os.Stdout, "Connection to the database failed")
return
}
fmt.Fprintf(os.Stdout, "You have connected to the database successfully")
sqlQuery := `INSERT INTO users ("user_id", "username", "password", "email", "gender", "gang") VALUES ($1, $2, $3, $4, $5, $6)`
_, err = db.Exec(sqlQuery, 1, "Ross8839", "rocky8839", "ross88399@hotmail.com", "Female", "Greengos")
if err != nil {
fmt.Fprintf(os.Stdout, "Failed to query db")
panic(err)
}
}
我希望以上代码没有错误,因为在我的Windows环境中可以工作,但我不想在Windows上进行开发。这一切都在我的Linux环境中,自从转移后...我遇到了这个问题。
以下是postgres用户在数据库上的权限。