简体   繁体   English

postgres:当从 node.js 调用时表明显存在时,关系不存在

[英]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.

相关问题 即使属性存在,Node.js hasOwnProperty也不起作用 - Node.js hasOwnProperty does not work even when the property exists 从不存在的站点请求HTTP响应时,Node.js脚本将中断 - Node.js script would break when requesting HTTP responses from a site that does not exist 从客户端调用node.js服务时出现竞态条件 - Race Condition when calling node.js service from client 节点js:浏览器中显示“不存在表”,但终端中是否存在表? - Node js: says “no table exists” in browser but table does exist in terminal? 从JS调用flash方法时,该函数不存在 - Function does not exist when calling flash method from JS 当我在 Node.js 上处理并发请求时,如何处理清楚? - When I handle concurrent request on Node.js, How to handle clearly? 错误:ER_TABLE_EXISTS_ERROR:使用 node.js 与 mysql 连接时 - Error: ER_TABLE_EXISTS_ERROR: when connecting with mysql using node.js 使用 node.js 和 mongoose 更新 Mongo DB 中的数据,即使集合不存在 - update data in Mongo DB even when collection does not exist using node.js and mongoose 在Javascript / Node.JS中调用匿名函数时的堆栈顺序 - Stack order when calling anonymous functions in Javascript/Node.JS 在node.js中调用递归函数时为空值 - Null value when calling a recursive function in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM