gpt4 book ai didi

javascript - 错误 : Error parsing url: undefined when migrating database to heroku

转载 作者:行者123 更新时间:2023-12-03 22:21:54 35 4
gpt4 key购买 nike

我正在使用 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 时实际上并没有收到应用程序错误

最佳答案

生产: {
use_env_variable: 'DATABASE_URL',
},

将您的生产更改为此并转到 heroku 设置环境变量

关于javascript - 错误 : Error parsing url: undefined when migrating database to heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53143809/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com