Sub*_*bbu 1 postgresql node.js sequelize.js
尝试使用模型从 postgres 表retail_lending.city_tax_reference 获取数据,但是当我tableName在查询中将双引号插入到表名中时使用该数据
const CityTax = this.config.define('foo', {
citytaxreference_skey: Sequelize.INTEGER,
city: Sequelize.STRING,
property_tax_rate: Sequelize.NUMERIC,
minimum_property_tax: Sequelize.INTEGER,
}, {
tableName: 'retail_lending.city_tax_reference',
timestamps: false,
});
CityTax.findAll({
attributes: ['citytaxreference_skey', 'city']
}).then((project) => {
console.log(project);
});
Run Code Online (Sandbox Code Playgroud)
quoteIdentifiers在建立连接期间设置为 false
SELECT citytaxreference_skey, city FROM retail_lending.city_tax_reference AS foo_ 期望模型在幕后运行查询上述查询在 postgres 命令行中运行
模型使用SELECT citytaxreference_skey, city FROM "retail_lending.city_tax_reference" AS foo
上面的查询在 postgres 命令行中不起作用,因为表名用引号引起来
输出:Unhandled rejection SequelizeDatabaseError: relation "retail_lending.city_tax_reference" does not exist
方言: postgres 方言版本:不确定(在线托管) 数据库版本:不确定(在线托管) Sequelize 版本: 4.39.0 使用最新版本进行测试:是,4.39.0
如果有任何解决方案,那就太好了,谢谢
有一个名为 schema 的属性,您可以在定义这样的模型时添加它
const CityTax = this.config.define('foo', {
citytaxreference_skey: Sequelize.INTEGER,
city: Sequelize.STRING,
property_tax_rate: Sequelize.NUMERIC,
minimum_property_tax: Sequelize.INTEGER,
}, {
tableName: 'city_tax_reference',
timestamps: false,
schema:'retail_lending'
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
956 次 |
| 最近记录: |