gpt4 book ai didi

node.js - 我正在使用 Node.js ORM Sequelize 及其命令行客户端,但我无法成功执行迁移

转载 作者:行者123 更新时间:2023-12-03 22:24:10 25 4
gpt4 key购买 nike

在我的应用程序中,我使用 Sequelize-CLI 设置表并运行迁移到 PostgreSQL 数据库。这是我的代码:

.sequelizerc

var path = require("path");

module.exports = {
'config': path.resolve('config', 'database.json'),
'migrations-path': path.resolve('db', 'migrate')
}

配置/数据库.json
{
"development": {
"username": "Sol",
"password": null,
"database": "experiments",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "Sol",
"password": null,
"database": "experiments",
"host": "127.0.0.1",
"dialect": "postgres"
}
}

我在我的模型目录中创建了两个模型,并使用 sequelize migration:create 创建了一个迁移文件在我的 db/migrate 目录中。最后我运行 sequelize db:migrate运行迁移,但是当我检查 PostgreSQL 数据库时,没有创建新表。运行命令后我得到这个响应:
Loaded configuration file "config/database.json".
Using environment "development".
at new module.exports.Sequelize (/Users/Sol/src/projects/tests/Node.js/toVisit/node_modules/sequelize/lib/sequelize.js:182:13)
at getSequelizeInstance (/usr/local/lib/node_modules/sequelize-cli/lib/tasks/db.js:203:10)
at getMigrator (/usr/local/lib/node_modules/sequelize-cli/lib/tasks/db.js:208:21)
at Object.module.exports.db:migrate.task (/usr/local/lib/node_modules/sequelize-cli/lib/tasks/db.js:23:7)
at Gulp.gulp.task.aliases (/usr/local/lib/node_modules/sequelize-cli/lib/helpers/gulp-helper.js:14:14)
at module.exports (/usr/local/lib/node_modules/sequelize-cli/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/usr/local/lib/node_modules/sequelize-cli/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/usr/local/lib/node_modules/sequelize-cli/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/usr/local/lib/node_modules/sequelize-cli/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at /usr/local/lib/node_modules/sequelize-cli/node_modules/gulp/bin/gulp.js:129:20
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3

最佳答案

事实证明,问题是 Sequelize-CLI 无法找到 PostgreSQL,因为它没有必要的模块 pgpg-hstore安装。我在通过我的服务器以编程方式使用 Sequelize 时发现了这一点。它给了我一个错误,其中一部分可以在这里看到:

throw new Error('The dialect ' + this.getDialect() + ' is not supported.
^
Error: The dialect postgres is not supported. (Error: Cannot find module 'pg-hstore')

从那里,一个简单的谷歌搜索让我得到了更详细的解释,现在我可以成功地运行我的迁移了!

关于node.js - 我正在使用 Node.js ORM Sequelize 及其命令行客户端,但我无法成功执行迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30553555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com