2014-02-27 34 views
9

在我config.json运行Sequelize -mPostgres的方言sequelize -m不工作

"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 

有没有在我的配置有问题,或者别的可能是这个问题?

回答

0

的医生说:

With the release of Sequelizev1.6.0, the library got independent from specific dialects. That mean, that you'll have to add the respective dialect library yourself. Another option is the use of the sequelize packages that ship the dialect libraries as well.

这时,你可能已经错过了需要的库,看到Sequelize docs

+1

我已经安装了pg模块,并在应用程序中运行sequelize。唯一不适用的地方是运行二进制迁移时。在这一点上,我得到'错误'。方言在整个应用程序的其余部分工作 – pjbr

1

我已经运行npm install --save pg里面的sequelize目录,现在一切都很好。

8

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

npm install -g pg 
+0

也为我工作! – jinavar1

1

对应用程序做了一个strace。看来Sequelize v2.x正在寻找'pg-native。

npm install -g pg-native

4

你需要有

$ 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:[email protected]: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' 
    }); 
}); 
1

我已经运行根@# “NPM安装PG PG-hstore sequelize --save” 并解决这个问题对我来说。谢谢 !