admin管理员组文章数量:1394082
When running the following code using Sequelize 5.21.3 to get a list of all the tables in PostgreSQL 11.5 database:
sequelize.query('SHOW TABLES', {
type: sequelize.QueryTypes.SHOWTABLES
})
.then(result => {
console.log(result)
})
we get the error:
Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"
What is the correct way to get a list of all the tables in the current PostgreSQL database using Sequelize?
Full Code
const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
sequelize = new Sequelize(config.database, config.username, config.password, config);
sequelize.query('SHOW Tables', {
type: sequelize.QueryTypes.SHOWTABLES
})
.then(result => {
console.log(result)
})
Full Error Stack
Executing (default): SHOW TABLES
Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"
at Query.formatError (/Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)
at /Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:72:18
at tryCatcher (/Users/nyxynyx/test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:439:21)
config
{
"development": {
"username": "postgres",
"password": "mypassword",
"database": "database_development",
"host": "127.0.0.1",
"dialect": "postgres",
"operatorsAliases": "0",
"define": {
"timestamps": false
}
},
...
When running the following code using Sequelize 5.21.3 to get a list of all the tables in PostgreSQL 11.5 database:
sequelize.query('SHOW TABLES', {
type: sequelize.QueryTypes.SHOWTABLES
})
.then(result => {
console.log(result)
})
we get the error:
Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"
What is the correct way to get a list of all the tables in the current PostgreSQL database using Sequelize?
Full Code
const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
sequelize = new Sequelize(config.database, config.username, config.password, config);
sequelize.query('SHOW Tables', {
type: sequelize.QueryTypes.SHOWTABLES
})
.then(result => {
console.log(result)
})
Full Error Stack
Executing (default): SHOW TABLES
Unhandled rejection SequelizeDatabaseError: unrecognized configuration parameter "tables"
at Query.formatError (/Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)
at /Users/nyxynyx/test/node_modules/sequelize/lib/dialects/postgres/query.js:72:18
at tryCatcher (/Users/nyxynyx/test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/nyxynyx/test/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/nyxynyx/test/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:439:21)
config
{
"development": {
"username": "postgres",
"password": "mypassword",
"database": "database_development",
"host": "127.0.0.1",
"dialect": "postgres",
"operatorsAliases": "0",
"define": {
"timestamps": false
}
},
...
Share
Improve this question
edited Jun 17, 2022 at 21:16
GMB
223k25 gold badges101 silver badges149 bronze badges
asked Jan 1, 2020 at 22:00
NyxynyxNyxynyx
63.9k163 gold badges507 silver badges856 bronze badges
1 Answer
Reset to default 6SHOW TABLES
is MySQL syntax, that is not supported in Postgres.
If you are running psql, you can use the \dt
mand.
A more generic solution is to query system view information_schema.tables
(which is available in more RDBMS):
select table_schema, table_name from information_schema.tables
You can also query pg_catalog.pg_tables
, which is Postgres-specific.
本文标签:
版权声明:本文标题:javascript - PostgreSQL SequelizeDatabaseError: unrecognized configuration parameter "tables" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744747256a2622959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论