我将Sequelize用作ORM,并且试图将数据库迁移到Heroku。运行heroku run sequelize db:migrate
我刚得到
Loaded configuration file "config/config.js".
Using environment "production".
ERROR: Error parsing url: undefined
这是我的配置文件的样子:
module.exports = {
"development": {
"username": "root",
"password": "password",
"database": "vueapp",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"use_env_variable": process.env.DATABASE_URL,
"dialect": "postgres",
"ssl": true,
"dialectOptions": {
"ssl": true
}
}
}
还有索引文件
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config')[env];
const User = require("./user")
const Hour = require('./hours');
const db = {
User,
Hour
};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(config.use_env_variable, config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
不能完全确定问题是什么。查看heroku日志,我看到一个throw new Error('Dialect needs to be explicitly supplied as of v4.0.0');
但是我已经在config.js文件中添加了方言。配置文件是.js文件还是.json文件有关系吗?
请澄清一下,实际的Web应用程序打开了,我可以看到我设置的错误处理程序。因此,在打开路线URL
时,实际上并没有收到应用程序错误答案 0 :(得分:0)
制作:{ use_env_variable:'DATABASE_URL', }
将生产更改为此,然后转到heroku设置环境变量
答案 1 :(得分:0)
你后来解决了吗