[英]postgres: relation does not exist when the table clearly exists when calling from node.js
so I psql'd and created table users;所以我 psql'd 并创建了表用户;
CREATE TABLE users (
id integer NOT NULL,
username text
);
I am able to grab rows by doing SELECT * FROM users;
我可以通过SELECT * FROM users;
However, when I use node.js with the library module pg to make calls I get the infamous relation does not exist.但是,当我使用 node.js 和库模块 pg 进行调用时,我得到臭名昭著的关系不存在。
const createQuery = {text: "INSERT INTO users(id, username) VALUES($1)",values: values}
const { rows } = await db.query(createQuery);
I wasn't running into this issue before a complete server migration.在完整的服务器迁移之前,我没有遇到这个问题。
The most likely option is that the table was created in a different schema than the default schema that you are using from node.js.最可能的选项是,表是在与您在 node.js 中使用的默认模式不同的模式中创建的。
You can search the schema your table belongs to by querying table information_schema.tables
:您可以通过查询表information_schema.tables
来搜索您的表所属的架构:
select table_schema from information_schema.tables where table_name = 'users';
With this information at hand, you can now qualify your table name with the proper schema name in the query that you are running from node.js.有了这些信息,您现在可以在从 node.js 运行的查询中使用正确的模式名称来限定您的表名。 Assuming that the schema name is myschema
, you would go:假设架构名称是myschema
,您将 go:
INSERT INTO myschema.users(id, username) VALUES($1)
By default when you don't specify any schema, postgres points out to public schema.默认情况下,当您不指定任何架构时,postgres 会指向公共架构。 Please use schema name/ database name as along with the table name.请使用模式名称/数据库名称以及表名称。 Make sure you have provided proper configurations of the database within your code.确保您在代码中提供了正确的数据库配置。 If the configurations are proper and even you no need to provided schema alias within the query.如果配置正确,甚至您不需要在查询中提供模式别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.