Reputation: 69
I'm most of the way there, has anyone gotten it to succesfully work? I only have the database working locally, after I git push heroku master the connection to the database fails.
Upvotes: 2
Views: 2460
Reputation: 76
Add 'Heroku Postgres' either through the Heroku CLI or under your project's Resources tab. It should also give you a DATABASE_URL
variable which you need for later.
Add pg module from Heroku. See the documentation here.
$ npm install --save --save-exact pg
Then, on the server, use the DATABASE_URL
we just got.
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
client.connect();
Put "use_env_variable": "DATABASE_URL"
on the config.json
file under "production". Should look like
"production": {
"use_env_variable": "DATABASE_URL"
...
}
Run migrations on Heroku. An option if you want to use sequelize-cli is:
$ npm install sequelize-cli --save
$ heroku run sequelize db:migrate
And it should work.
Upvotes: 6