【发布时间】:2016-12-04 20:42:32
【问题描述】:
我使用 postgresql 和 node.js 创建了一个 node express 应用程序。我决定把它放在heroku上。我使用 heroku 的插件创建了我的 postgresql 数据库。我可以看到我的数据库(用户名/密码/uri 等)
我可以 ping heroku 应用程序,但是当我尝试创建用户时,我收到 400 错误。我检查了日志,问题是我无法创建表。
这是我的 app.js,它应该使用 ORM 创建模型。
var db = require('sequelize-connect');
// Database sequelize
var connectionString;
var username;
var password;
var database;
if (process.env.NODE_ENV === 'development'){
connectionString = global.localConnectionString;
database = global.nameDatabase_development;
username = global.usernameDatabase_development;
password = global.passwordDatabase_development;
}else{
connectionString = global.productionConnectionString;
database = global.nameDatabase_production;
username = global.usernameDatabase_production;
password = global.passwordDatabase_production;
}
var sequelize = new Sequelize(connectionString);
// Model ORM configurations
var discover = path.join(__dirname, 'models');
var matcher = function (file) {
return true;
}
var orm = new db(
database,
username,
password,
{
dialect: 'postgres',
port: 5432,
force: true
},
discover,
matcher
);
我从 Heroku 页面获得了数据库名称/用户名/密码。我必须在heroku上手动创建表吗?我认为 sequelize-connect 用于此目的?如何在 heroku 上创建表格?
【问题讨论】:
标签: node.js postgresql heroku orm sequelize.js