所以我 psql 并创建了表用户;
CREATE TABLE users (
id integer NOT NULL,
username text
);
我可以通过 SELECT * FROM users;
但是,当我使用带有库模块 pg 的 node.js 进行调用时,我得到了臭名昭著的关系不存在。
const createQuery = {text: "INSERT INTO users(id, username) VALUES($1)",values: values}
const { rows } = await db.query(createQuery);
在完成服务器迁移之前,我没有遇到过这个问题。
最佳答案
最可能的选择是该表是在与您从 node.js 使用的默认模式不同的模式中创建的。
您可以通过查询表 information_schema.tables
来搜索您的表所属的架构:
select table_schema from information_schema.tables where table_name = 'users';
有了这些信息,您现在可以在从 node.js 运行的查询中使用正确的模式名称来限定您的表名。假设模式名称是 myschema
,您将:
INSERT INTO myschema.users(id, username) VALUES($1)
关于javascript - postgres : relation does not exist when the table clearly exists when calling from node. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61379682/