所以我 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/
相关文章:
flutter - 如何在 Flutter 中禁用 SnackBar 的淡入/淡出动画?
ios - 如何在 SwiftUI 中更新 TextField 的值?
python - 为什么在 Python 中从不同路径调用类时 __class__ 不同?
reactjs - Ant Design 如何处理 Form.List 从底层数据结构访问值?
google-app-engine - 将 AppEngine 中的传入请求路由到不同版本
angular - JSDom karma Angular 设置
python - 当没有 activate.bat 并且我是凡人时,如何在虚拟环境中的任务调度程序中