title: "Self signed certificate" error on Heroku running sequelize db:migrate
body: <p>I have a Node / Express app with a Postgres database that functions perfectly on my local machine, but I'm struggling to get it up and running on Heroku. The problem occurs after I push to Heroku -- which builds successfully -- when I then try to run <code>heroku run sequelize db:migrate</code>. The error is:</p>
  <pre><code>ERROR: self signed certificate
  </code></pre>
  <h3>My setup:</h3>
  <ul>
  <li>Node v15.12.0</li>
  <li>Postgres database (&quot;Heroku Postgres&quot; add-on)</li>
  <li>pg v8.5.1</li>
  <li>sequelize v6.6.2</li>
  <li>sequelize-cli v6.2.0</li>
  </ul>
  <h3>My Sequelize connection parameters:</h3>
  <pre><code>{
    &quot;development&quot;: {
      &quot;username&quot;: &quot;XXXXXX&quot;,
      &quot;password&quot;: &quot;XXXXXX&quot;,
      &quot;database&quot;: &quot;party_playlist&quot;,
      &quot;host&quot;: &quot;127.0.0.1&quot;,
      &quot;dialect&quot;: &quot;postgres&quot;
    },
    &quot;production&quot;: {
      &quot;use_env_variable&quot;: &quot;DATABASE_URL&quot;,
      &quot;dialect&quot;: &quot;postgres&quot;,
      &quot;dialectOptions&quot;: {
        &quot;ssl&quot;: {
           &quot;require&quot;: &quot;true&quot;,
           &quot;rejectUnauthorized&quot;: &quot;false&quot;
        }
      }
    }
  }
  </code></pre>
  <p>Many posts speak to this issue (GitHub: <a href="https://github.com/brianc/node-postgres/issues/2009" rel="nofollow noreferrer">1</a> | <a href="https://github.com/sequelize/sequelize/issues/12083" rel="nofollow noreferrer">2</a> | <a href="https://github.com/strapi/strapi/issues/5671" rel="nofollow noreferrer">3</a>, StackOverflow: <a href="https://stackoverflow.com/questions/58965011/sequelizeconnectionerror-self-signed-certificate">1</a> | <a href="https://stackoverflow.com/questions/61350186/how-to-solve-the-database-connection-error-sequelizeconnectionerror">2</a> | <a href="https://stackoverflow.com/questions/61691212/nodejs-and-express-error-self-signed-certificate">3</a>), and most point to pg v8 as being the root of the problem; however, none of the recommended solutions have worked for me.</p>
  <h3>What I've tried so far:</h3>
  <ol>
  <li>Adding <code>rejectUnauthorized: false</code> to my Sequelize connection params</li>
  <li>Adding <code>ssl:true</code> to the config outside of dialectOptions</li>
  <li>Adding <code>NODE_TLS_REJECT_UNAUTHORIZED=0</code> to my Heroku environment variables</li>
  <li>Adding <code>PGSSLMODE=no-verify</code> to my Heroku environment variables</li>
  <li>Toggling Heroku's <code>Automatic Certificate Management</code> feature on/off</li>
  <li>Rolling back to pg v7 (various subversions)</li>
  </ol>
  <p>1-5 have no effect, and rolling back to pg v7 breaks the app (locally, any attempted reads/writes to the database hang with no error message; on heroku, the db:migrate command runs without an error message, but the db isn't updated). I assume that pg v7 is incompatible with my Node version or some other package version in my project, but I have no idea how to figure out what a compatible version set would be other than by trial and error, which isn't feasible. Also, as a side note, this is a hobby project so I'm not worried about MITM attacks.</p>
  <p>Interestingly, I'm able to connect to my Heroku database just fine when I run <code>heroku pg:psql</code>!</p>
  <p>Any ideas how I can fix this one? Any and all help would be much appreciated!</p>