Postgres方言不适用于sequelize -m

时间:2014-02-27 23:46:57

标签: node.js postgresql express sequelize.js

运行Sequelize -m

在我的config.json

"development": {
    "username": "root",
    "password": null,
    "database": "**********",
    "dialect": "postgres",
    "protocol": "postgres",
    "port": 5432,
    "host": "127.0.0.1"
},

收到错误:

sequelize -m
Loaded configuration file "config/config.json".
Using environment "development".

/usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10
    throw new Error("The dialect " + sequelize.getDialect() + " is not support
          ^
Error: The dialect postgres is not supported.
    at new module.exports (/usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10:11)
    at new module.exports.Sequelize (/usr/local/lib/node_modules/sequelize/lib/sequelize.js:128:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/sequelize/bin/sequelize:225:27)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

我的配置中是否存在问题或其他可能存在问题的问题?

7 个答案:

答案 0 :(得分:13)

我偶然发现了同样的问题。您应该全局安装pg模块。这是命令:

npm install -g pg

答案 1 :(得分:8)

都能跟得上!

您需要安装pg-hstore。

见这里:https://github.com/sequelize/sequelize/issues/2949

答案 2 :(得分:6)

你需要

$ npm install pg --save
$ npm install pg-hstore --save
$ npm install sequelize --save

另外单独创建数据库,sequelize不会为你创建数据库。

var Sequelize = require("sequelize");

// make sure you have created the database using pg Admin III 
var sequelize = new Sequelize("postgres://postgres:postgres@localhost:5432/yourdbname");

var Person = sequelize.define('person', {
  firstName: {
    type: Sequelize.STRING
  },
  lastName: {
    type: Sequelize.STRING
  }
});

Person.sync({force: true}).then(function () {
  return Person.create({
    firstName: 'jj',
    lastName: 'Hancock'
  });
});

答案 3 :(得分:4)

我在sequelize目录中运行npm install --save pg,一切都很好。

答案 4 :(得分:1)

对应用程序进行了分析。似乎Sequelize v2.x正在搜索&#39; pg-native。

npm install -g pg-native

答案 5 :(得分:1)

我已经运行root @#“ npm install pg pg-hstore sequelize --save ” 它解决了我的问题。谢谢 !

答案 6 :(得分:0)

医生说:

  

随着Sequelizev1.6.0的发布,该库独立于   特定的方言。这意味着,您必须添加相应的   方言图书馆自己。另一种选择是使用续集   也提供方言库的包。

然后您可能错过了要求图书馆,请参阅Sequelize docs