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