I';m使用Node.js ORM Sequelize及其命令行客户端和I';我很难成功地执行迁移

I';m使用Node.js ORM Sequelize及其命令行客户端和I';我很难成功地执行迁移,node.js,postgresql,sequelize.js,Node.js,Postgresql,Sequelize.js,在我的应用程序中,我使用Sequelize CLI设置表并运行到PostgreSQL数据库的迁移。这是我的密码: .后遗症 var path = require("path"); module.exports = { 'config': path.resolve('config', 'database.json'), 'migrations-path': path.resolve('db', 'migrate') } config/database.json { "developme

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

.后遗症

var path = require("path");

module.exports = {
  'config': path.resolve('config', 'database.json'),
  'migrations-path': path.resolve('db', 'migrate')
}
config/database.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"
    } 
}
我在models目录中创建了两个模型,并在db/migrate目录中使用
sequelize migration:create
创建了一个迁移文件。最后,我运行
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,因为它没有安装必要的模块
pg
pg 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')
从那里,一个简单的谷歌搜索让我得到了更详细的解释,现在我可以成功地运行迁移了

安装pg hstore:

并在config/database.json中设置方言:

npm install pg-hstore --save
 dialect: 'postgres'