简体   繁体   English

如何解决“未处理的拒绝SequelizeDatabaseError:关系“ ABC”不存在”?

[英]How to fix “Unhandled rejection SequelizeDatabaseError: relation ”ABC“ does not exist”?

I'm trying to fetch data from an existing postgres db which has a couple of tables in it. 我正在尝试从现有的postgres db中获取数据,该数据库中有几个表。 While the connection to the database is carried out successfully, I cannot seem to carry out any test queries for example 与数据库的连接成功完成后,我似乎无法进行任何测试查询,例如

Model.findAll().then(table =>{ console.log(table)}

I have tried appending the Schema Name to the model definition like 我尝试将模式名称附加到模型定义

const Model = sequelize.define('Schema.ABC', { ....}}

which throws the same error as the title suggests 引发与标题相同的错误

I have also tried appending the Schema name to the query but it throws a syntax error and the code doesn't execute 我也尝试过将架构名称附加到查询中,但是会引发语法错误,并且代码无法执行

Model.findAll().then('Schema.ABC' => { console.log(Schema.ABC)}

If the table does need to have Schema name appended to it, then I would also like to know how to achieve it. 如果该表确实需要附加模式名称,那么我也想知道如何实现它。

Below is a fragment of my code 以下是我的代码片段

const Model = sequelize.define('ABC',{
    CompanyName: Sequelize.STRING,
    createdAt: Sequelize.DATE,
    updatedAt: Sequelize.DATE
},
{
    // tableName: `"Schema"."ABC"`,
    freezeTableName: true
});

...
Model.removeAttribute('id');

Model.findAll().then(ABC => {
    console.log(ABC)
})

You should define your schema like this, leaving the tableName property uncommented: 您应该像这样定义架构,使tableName属性不加注释:

const ABC = sequelize.define('ABC',{
    CompanyName: Sequelize.STRING,
    createdAt: Sequelize.DATE,
    updatedAt: Sequelize.DATE
  },
  {
    freezeTableName: true,
    tableName: 'ABC',
  });

And use this, inside of an asynchronous function: 并在异步函数内部使用此函数:

async function findAllABC() {
  await ABC.findAll().then((result) => {
    console.log(`The result is: '${result}'`);
  });
}

findAllABC();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的拒绝 SequelizeDatabaseError:关系“用户”不存在 - Unhandled rejection SequelizeDatabaseError: relation "users" does not exist 未处理的拒绝错误:关系'dbname'不存在 - Unhandled rejection error: relation 'dbname' does not exist SequelizeDatabaseError: 关系表不存在 - SequelizeDatabaseError: relation table does not exist 未处理的拒绝SequelizeDatabaseError - Unhandled Rejection SequelizeDatabaseError Postgres未处理的拒绝错误:关系“ public.role”不存在 - Postgres Unhandled rejection error: relation “public.role” does not exist 未处理的拒绝 SequelizeDatabaseError:未选择数据库 - Unhandled rejection SequelizeDatabaseError: No database selected 未处理的拒绝SequelizeDatabaseError:关系“bar”的列“foo_bar”已存在 - Unhandled rejection SequelizeDatabaseError: column “foo_bar” of relation “bar” already exists 渲染使节点应用程序崩溃,错误为“ SequelizeDatabaseError:关系“ orders”不存在” - render crashes the Node app with error “SequelizeDatabaseError: relation ”orders“ does not exist” SequelizeDatabaseError:Koa.js 框架中不存在关系“用户” - SequelizeDatabaseError: relation "users" does not exist in Koa.js framework 如何修复nodejs中未处理的承诺拒绝? - How to fix Unhandled promise rejection in nodejs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM