title: Sequelize Error: Relation does not exist
body: <p>I am able to use <code>sequelize.js</code> to do an <code>INSERT INTO</code> command for a table in my development database, but not in my test database.</p>
  
  <p>Despite researching thoroughly, I have not been able to resolve the issue.</p>
  
  <p>A similar question has been posted here, though I have not been able to answer my question with the answers:
  <a href="https://stackoverflow.com/questions/28844617/sequelize-with-postgres-database-not-working-after-migration-from-mysql">sequelize with postgres database not working after migration from mysql</a></p>
  
  <p>Here is my relevant migration file:</p>
  
  <pre><code>'use strict';
  module.exports = {
    up: (queryInterface, Sequelize) =&gt; {
      return queryInterface.createTable('Trees', {
        id: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: Sequelize.INTEGER
        },
        title: {
          type: Sequelize.STRING,
          allowNull: false
        },
        content: {
          type: Sequelize.STRING(10000),
          allowNull: false
        },
        createdAt: {
          allowNull: false,
          type: Sequelize.DATE
        },
        updatedAt: {
          allowNull: false,
          type: Sequelize.DATE
        }
      });
    },
    down: (queryInterface, Sequelize) =&gt; {
      return queryInterface.dropTable('Trees');
    }
  };
  </code></pre>
  
  <p>Here is the model file:</p>
  
  <pre><code>'use strict';
  module.exports = (sequelize, DataTypes) =&gt; {
    var Tree = sequelize.define('Tree', {
      title: {
        type: DataTypes.STRING,
        allowNull: false
      },
      content: {
        type: DataTypes.STRING(10000),
        allowNull: false
      }
    }, {});
    Tree.associate = function(models) {
      // associations can be defined here
    };
    return Tree;
  };
  </code></pre>
  
  <p>Here is the code that accesses the database:</p>
  
  <pre><code>const setTree = (treeVal, callback) =&gt; {
    console.log(`this would be the part`);
    Tree.create({
      title: 'Tree',
      content: JSON.stringify(treeVal)
    })
    .then((treeStr) =&gt; {
      let primaryTopics = JSON.parse(treeStr.content);
      callback(null, primaryTopics);
    })
    .catch((err) =&gt; {
      callback(err);
    });
  }
  </code></pre>
  
  <p>This is exported in the <code>module.exports</code> method:</p>
  
  <pre><code>  callTree(callback) {
      return Tree.findOne({
        where: {
          title: 'Tree'
        }
      })
      .then((treeStr) =&gt; {
        if (treeStr === null) {
          return callback(`not defined yet`);
        }
        let primaryTopics = treeStr.content;
        primaryTopics = JSON.parse(primaryTopics);
        callback(null, primaryTopics);
      })
      .catch((err) =&gt; {
        callback(err);
      });
    }
  </code></pre>
  
  <p>And I'm pulling this method for an integration test here (the PrimaryTopic table is in the same database, and I receive no errors trying to run it):</p>
  
  <pre><code>  beforeEach((done) =&gt; {
      this.primaryTopic;
      sequelize.sync({force: true}).then((res) =&gt; {
  
        PrimaryTopic.create({
          title: 'Title: Hello World',
          content: '&lt;p&gt;Content: Hello World&lt;/p&gt;'
        })
        .then((primaryTopic) =&gt; {
          this.primaryTopic = primaryTopic;
          treeQueries.buildTree((err, res) =&gt; {
            if (err) {
              console.error(err);
            }
          });
          done();
        })
        .catch((err) =&gt; {
          console.log(err);
          done();
        });
  
      });
    });
  </code></pre>
  
  <p>I've searched through all the code for possible errors, but haven't found anything yet. </p>
  
  <p>I can use <code>psql</code> to access the <code>Trees</code> table in the test database, though it is empty.</p>
  
  <p>I can use the same code to insert a value into the <code>Trees</code> table in the development database with no issues.</p>
  
  <p>Here is the error I receive when I try to run a test (using jasmine.js for testing):</p>
  
  <pre><code>{ SequelizeDatabaseError: relation "Trees" does not exist
      at Query.formatError (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/sequelize/lib/dialects/postgres/query.js:363:16)
      at query.catch.err (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/sequelize/lib/dialects/postgres/query.js:86:18)
      at tryCatcher (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/promise.js:512:31)
      at Promise._settlePromise (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/promise.js:569:18)
      at Promise._settlePromise0 (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/promise.js:614:10)
      at Promise._settlePromises (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/promise.js:689:18)
      at Async._drainQueue (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/async.js:133:16)
      at Async._drainQueues (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/async.js:143:10)
      at Immediate.Async.drainQueues [as _onImmediate] (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/bluebird/js/release/async.js:17:14)
      at runCallback (timers.js:756:18)
      at tryOnImmediate (timers.js:717:5)
      at processImmediate [as _immediateCallback] (timers.js:697:5)
    name: 'SequelizeDatabaseError',
    parent: 
     { error: relation "Trees" does not exist
      at Connection.parseE (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:553:11)
      at Connection.parseMessage (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:378:19)
      at Socket.&lt;anonymous&gt; (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:119:22)
      at Socket.emit (events.js:160:13)
      at addChunk (_stream_readable.js:269:12)
      at readableAddChunk (_stream_readable.js:256:11)
      at Socket.Readable.push (_stream_readable.js:213:10)
      at TCP.onread (net.js:599:20)
       name: 'error',
       length: 104,
       severity: 'ERROR',
       code: '42P01',
       detail: undefined,
       hint: undefined,
       position: '13',
       internalPosition: undefined,
       internalQuery: undefined,
       where: undefined,
       schema: undefined,
       table: undefined,
       column: undefined,
       dataType: undefined,
       constraint: undefined,
       file: 'parse_relation.c',
       line: '1160',
       routine: 'parserOpenTable',
       sql: 'INSERT INTO "Trees" ("id","title","content","createdAt","updatedAt") VALUES (DEFAULT,\'Tree\',\'[{"title":"Title: Hello World","id":1,"secondaryTopics":[]}]\',\'2018-08-14 06:38:37.243 +00:00\',\'2018-08-14 06:38:37.243 +00:00\') RETURNING *;' },
    original: 
     { error: relation "Trees" does not exist
      at Connection.parseE (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:553:11)
      at Connection.parseMessage (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:378:19)
      at Socket.&lt;anonymous&gt; (/home/siddhartha/Documents/01-Studio/01-Commercial-Public/01-Komodo/2018-resources/node_modules/pg/lib/connection.js:119:22)
      at Socket.emit (events.js:160:13)
      at addChunk (_stream_readable.js:269:12)
      at readableAddChunk (_stream_readable.js:256:11)
      at Socket.Readable.push (_stream_readable.js:213:10)
      at TCP.onread (net.js:599:20)
       name: 'error',
       length: 104,
       severity: 'ERROR',
       code: '42P01',
       detail: undefined,
       hint: undefined,
       position: '13',
       internalPosition: undefined,
       internalQuery: undefined,
       where: undefined,
       schema: undefined,
       table: undefined,
       column: undefined,
       dataType: undefined,
       constraint: undefined,
       file: 'parse_relation.c',
       line: '1160',
       routine: 'parserOpenTable',
       sql: 'INSERT INTO "Trees" ("id","title","content","createdAt","updatedAt") VALUES (DEFAULT,\'Tree\',\'[{"title":"Title: Hello World","id":1,"secondaryTopics":[]}]\',\'2018-08-14 06:38:37.243 +00:00\',\'2018-08-14 06:38:37.243 +00:00\') RETURNING *;' },
    sql: 'INSERT INTO "Trees" ("id","title","content","createdAt","updatedAt") VALUES (DEFAULT,\'Tree\',\'[{"title":"Title: Hello World","id":1,"secondaryTopics":[]}]\',\'2018-08-14 06:38:37.243 +00:00\',\'2018-08-14 06:38:37.243 +00:00\') RETURNING *;' }
  </code></pre>
  
  <p><a href="https://github.com/KomodoPlatform/resources/tree/v0.0.14" rel="noreferrer">Here's a link to the full repository.</a></p>