2

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.

1 Answer 1

6
  1. 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.

  2. 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();
    
  3. Put "use_env_variable": "DATABASE_URL" on the config.json file under "production". Should look like

    "production": {
        "use_env_variable": "DATABASE_URL"
        ...
    }
    
  4. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.