title: Unhanded rejection error :Transaction query already complete - knex, express.js
body: <p>I was trying to check for a value in a table first, and if it exists, delete a row in another table and insert this new data into that table.</p>
  
  <p>I used a transaction with a select, del(), and a insert command</p>
  
  <pre class="lang-js prettyprint-override"><code>db.transaction(trx =&gt; {
    return trx('users')
      .where({ username: user.username })
      .select('username')
      .returning('username')
  
      .then(retData =&gt; {
        retUserName = retData[0];
  
        db('profile')
          .where({ username: user.username })
          .del()
          .then(retData =&gt; {
            return trx
              .insert(profileData)
              .into('profile')
              .returning('*');
          });
      })
      .then(retData =&gt; {
        res.json({ ProfileData: profileData });
      })
      .then(trx.commit)
      .catch(trx.rollback);
  }).catch(err =&gt; res.status(400).json('unable to create profile'));
  </code></pre>
  
  <p>I get this error Unhanded rejection error:Transaction query already completed</p>
  
  <p>but the data hasn't been added to the table.</p>