在 GoLang 中對我的數據庫運行任何 sql 查詢時,出現以下錯誤,有誰知道是否還有其他我可以嘗試解決的問題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", "[email protected]", "Female", "Greengos")if err != nil { fmt.Fprintf(os.Stdout, "Failed to query db") panic(err)}}我希望上面的代碼沒有錯誤,因為我在我的 Windows 環境中工作,但我不想使用 Windows 進行開發。這都是在我的 Linux 環境中,并且自從搬過來......我遇到了這個問題。以下是 postgres 用戶對數據庫的權限https://i.imgur.com/ZqFUrek.png
- 2 回答
- 0 關注
- 346 瀏覽
添加回答
舉報
0/150
提交
取消