title: Unhandled rejection TypeError: Role.Create is not a function error
body: <p>I have got stuck on a .create is not a function error when I am trying to repopulate my database when I restart nodemon. I have had this working previously and all the tables populated fine I keep getting flagged this error. I am using Node, Express, Sequelize and Postgres pgAdmin4.</p>
  <p>I have read on similar topics that a ; in node can cause errors like this but i have tried a few things and still get the same error.</p>
  <pre><code>//const Sequelize = require('sequelize')
  const express = require(&quot;express&quot;);
  const bodyParser = require (&quot;body-parser&quot;);
  // const { Sequelize, Op, Model, DataTypes } = require(&quot;sequelize&quot;);
  // import authRoute from './server/routes/auth.routes';
  // import postRoutes from './server/routes/diveLog.routes';
  const cors = require(&quot;cors&quot;);
  
  // creates an en express app
  const app = express();
  
  // set origin to 5002
  // var corsOptions = {
  //    origin: &quot;http://localhost:5002&quot;
  //}
   // add bp and cors using api.use method
  
  // parse requests of content type app/json
  // app.use(cors(corsOptions));
  
  app.use((req, res, next) =&gt; {
      res.header('Access-Control-Allow-Origin', '*');
      res.header(
          'Access-Control-Allow-Headers',
          'Origin, X-Requested-With, Content-Type, Accept',
      );
      next();
  });
  
  // parse requests of content-type
  app.use(bodyParser.json());
  
  //bp used to process form data as json
  app.use(bodyParser.urlencoded({ extended: true }));
  
  //database
  const db = require(&quot;./server/models&quot;);
  //const sequelize = require(&quot;pg&quot;);
  const Role = db.userRole;
  //const DivingSchool = db.approvedDivingSchool;
  const Current = db.currentLevel;
  const DiveType = db.diveType;
  const DiveRegion = db.diveRegion;
  const Visibility = db.visibilityLevel;
  const DiveAgency = db.diveAgency;
  const Certifications = db.diveCertification;
  const MarineType = db.marineType;
  
  //const user = db.userLogin;
  
  try {
      db.sequelize.authenticate();
      console.log('Connection made to the database made.');
      } catch (error) {
      console.error('unable to connect:', error);
  }
  
  // db.sequelize.sync();
  // force: true will drop the table if it already exists
  db.sequelize.sync({ force: false })
      .then(() =&gt; {
      console.log(`Drop and resync database with { force: true }`)
      initial()
  });
  
  // simple route
  app.get('/', (req, res) =&gt; {
      res.json({ message: &quot;connected to the sustainable scuba database.&quot; });
  });
  
  // routes
  require('./server/routes/auth.routes')(app);
  require('./server/routes/user.routes')(app);
  require('./server/routes/diveLog.routes')(app);
  require('./server/routes/diveSchool.routes')(app);
  
  // set port, listen for requests
  const PORT = process.env.PORT || 5000;
  app.listen(PORT, () =&gt; {
      console.log(`Server is now running on PORT ${PORT}.`);
  });
  
  
  function initial() {
  
       Role.create({
              userRoleID: 1,
              userRoleName: &quot;User&quot;
           });
           Role.create({
                 userRoleID: 2,
                 userRoleName: &quot;School&quot;
           });
           Role.create({
                 userRoleID: 3,
                 userRoleName: &quot;SiteAdmin&quot;
           });
           Role.create({
                 userRoleID: 4,
                 userRoleName: &quot;SuperUser&quot;
           });
  }
  </code></pre>
  <p>Error message:</p>
  <pre><code>Unhandled rejection TypeError: Role.create is not a function
  
      at initial (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\server.js:86:11)
  
      at C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\server.js:63:5
  
      at tryCatcher (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\bluebird\js\relea
  
  se\util.js:16:23)
  
      at Promise._settlePromiseFromHandler (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_mo
  
  dules\bluebird\js\release\promise.js:547:31)
  
      at Promise._settlePromise (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\blueb
  
  ird\js\release\promise.js:604:18)
  
      at Promise._settlePromise0 (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\blue
  
  bird\js\release\promise.js:649:10)
  
      at Promise._settlePromises (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\blue
  
  bird\js\release\promise.js:729:18)
  
      at _drainQueueStep (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\bluebird\js\
  
  release\async.js:93:12)
  
      at _drainQueue (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\bluebird\js\rele
  
  ase\async.js:86:9)
  
      at Async._drainQueues (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\sequelize\node_modules\bluebird\
  
  js\release\async.js:102:5)
  
      at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\James Greene\WebstormProjects\softwaredevproject\SustainableScuba\backend\node_modules\seque
  
  lize\node_modules\bluebird\js\release\async.js:15:14)
  
      at processImmediate (internal/timers.js:439:21)
  </code></pre>
  <p>index.js</p>
  <pre><code>const config = require(&quot;../../config/db.config.js&quot;);
  
  const Sequelize = require(&quot;sequelize&quot;);
  const sequelize = new Sequelize(
        config.DB,
        config.USER,
        config.PASSWORD,
  
      {
        host: config.HOST,
        dialect: config.dialect,
        operatorsAliases: false,
          //logging: (...msg) =&gt; console.log(msg),
  
          pool: {
              max: config.pool.max,
              min: config.pool.min,
              acquire: config.pool.acquire,
              idle: config.pool.idle
          }
        }
       );
  
  const db = {};
  
  db.Sequelize = Sequelize;
  db.sequelize = sequelize;
  
  db.userLogin = require(&quot;./userLogin.model&quot;)(sequelize, Sequelize);
  db.userRole = require(&quot;./userRole.model&quot;)(sequelize, Sequelize);
  db.diveLog = require(&quot;./diveLog.model.js&quot;)(sequelize, Sequelize);
  db.visibilityLevel = require(&quot;./visibility.model.js&quot;)(sequelize, Sequelize);
  db.diveType = require(&quot;./diveType.model.js&quot;)(sequelize, Sequelize);
  db.currentLevel = require(&quot;./currentLevel.model.js&quot;)(sequelize, Sequelize);
  db.approvedDivingSchool = require(&quot;./approvedDivingSchool.model.js&quot;)(sequelize, Sequelize);
  db.diveRegion = require(&quot;./diveRegion.model.js&quot;)(sequelize, Sequelize);
  db.diveAgency = require(&quot;./diveAgency.model&quot;)(sequelize, Sequelize);
  db.diveCertification = require(&quot;./diveCertifications.model&quot;)(sequelize, Sequelize);
  db.marineLife = require(&quot;./marineLife.model&quot;)(sequelize, Sequelize);
  db.diveSpot = require(&quot;./diveLog.model&quot;)(sequelize, Sequelize);
  db.article = require(&quot;./articles.model&quot;)(sequelize, Sequelize);
  
  
  
  /* db.userRole.belongsTo(db.userLogin, {
    through: &quot;fk_userRoles&quot;,
    foreignKey: &quot;userRoleID&quot;,
    otherKey: &quot;userRole&quot;
  });
  //db.userLogin.belongsTo(db.userRole, {
  //  through: &quot;fk_userRoles&quot;,
  //  foreignKey: &quot;userRole&quot;,
  //  otherKey: &quot;userRoleID&quot;
  //});
  db.diveLog.belongsTo(db.visibilityLevel, {
      through: &quot;fk_visibility&quot;,
      foreignKey: &quot;diveVisibilityID&quot;,
      otherKey: &quot;visibilityID&quot;
  });
  //db.visibilityLevel.belongsTo(db.diveLog, {
  //    through: &quot;fk_visibility&quot;,
  //    foreignKey: &quot;visibilityID&quot;,
  //    otherKey: &quot;diveVisibilityID&quot;
  //});
  db.diveLog.belongsTo(db.currentLevel, {
      through: &quot;fk_current&quot;,
      foreignKey: &quot;diveCurrentID&quot;,
      otherKey: &quot;currentID&quot;
  });
  db.currentLevel.belongsTo(db.diveLog, {
      through: &quot;fk_visibility&quot;,
      foreignKey: &quot;currentID&quot;,
      otherKey: &quot;diveCurrentID&quot;
  });
  db.diveLog.belongsTo(db.approvedDivingSchool, {
      through: &quot;fk_divingSchool&quot;,
      foreignKey: &quot;diveSchoolNameID&quot;,
      otherKey: &quot;diveSchoolID&quot;
  });
  db.approvedDivingSchool.belongsTo(db.diveLog, {
      through: &quot;fk_divingSchool&quot;,
      foreignKey: &quot;diveSchoolID&quot;,
      otherKey: &quot;diveSchoolNameID&quot;
  });
  db.diveLog.belongsTo(db.diveType, {
      through: &quot;fk_diveType&quot;,
      foreignKey: &quot;diveTypeID&quot;,
      otherKey: &quot;diveTypeID&quot;
  });
  db.diveType.belongsTo(db.diveLog, {
      through: &quot;fk_diveType&quot;,
      foreignKey: &quot;diveTypeID&quot;,
      otherKey: &quot;diveTypeID&quot;
  });
  db.diveLog.belongsTo(db.userLogin, {
      through: &quot;fk_userID&quot;,
      foreignKey: &quot;diverUserNumber&quot;,
      otherKey: &quot;userID&quot;
  });
  db.userLogin.belongsTo(db.diveLog, {
      through: &quot;fk_userID&quot;,
      foreignKey: &quot;userID&quot;,
      otherKey: &quot;diverUserNumber&quot;
  });
  db.approvedDivingSchool.belongsTo(db.diveLocation, {
      through: &quot;fk_diveLocation&quot;,
      foreignKey: &quot;diveSchoolLocation&quot;,
      otherKey: &quot;diveLocationID&quot;
  });
  db.diveLocation.belongsTo(db.approvedDivingSchool, {
      through: &quot;fk_diveLocation&quot;,
      foreignKey: &quot;diveLocationID&quot;,
      otherKey: &quot;diveSchoolLocation&quot;
  });
   */
  
  db.userRole = [&quot;User&quot;, &quot;School&quot;, &quot;SiteAdmin&quot;, &quot;SuperUser&quot;];
  db.diveType = [&quot;Recreational&quot;, &quot;Training&quot;, &quot;Night Dive&quot;, &quot;Deep Dive&quot;, &quot;Drift&quot;, &quot;Wreck&quot;, &quot;Cave&quot;, &quot;Reef&quot;, &quot;Photo&quot;, &quot;Research&quot;];
  db.VisibilityLevel = [&quot;Bad &lt; 5 m&gt;&quot;, &quot;Average 5-10 m&quot;, &quot;Good 10-25 m&quot;, &quot;Excellent &gt; 25 m&quot;];
  db.currentLevel = [&quot;Light &gt; 1 knot&quot;, &quot;Medium 1-2 knots&quot;, &quot;Strong 2-3 knots&quot;, &quot;Extreme &gt; 2 knots&quot;];
  db.diveRegion = [&quot;Europe&quot;, &quot;North America&quot;, &quot;South America&quot;, &quot;Africa&quot;, &quot;Oceania&quot;, &quot;Asia&quot;];
  db.userLogin = [&quot;Dummy&quot;, &quot;dummy&quot;, &quot;dummy@dummy.com&quot;, &quot;Dummy&quot;, &quot;Dummy&quot;];
  db.diveAgency = [&quot;PADI&quot;, &quot;SSI&quot;, &quot;NAUI&quot;, &quot;SDI&quot;];
  db.marineType = [&quot;Cephalopods, crustaceans &amp; other shellfish&quot;, &quot;Corals and other invertebrates&quot;, &quot;Marine mammals&quot;, &quot;Ocean fishes&quot;, &quot;Sea Turtles &amp; Reptiles&quot;, &quot;Sharks and Rays&quot;, &quot;Marine Science and Ecosystems&quot;];
  db.diveCertification = [&quot;Open Water&quot;, &quot;Open Water Adv&quot;, &quot;Open Water Instructor&quot;, &quot;Divemaster&quot;, &quot;Divemaster&quot;, &quot;Freediver Basic&quot;, &quot;Freediver Adv&quot;, &quot;Freediver Instructor&quot;, &quot;Freediver Master&quot;, &quot;Dive Theory&quot;, &quot;Digital Underwater Photographer&quot;, &quot;Underwater Videographer&quot;, &quot;Deep Diver&quot;, &quot;Night Diver&quot;, &quot;Ice Diver&quot;, &quot;Cavern Diver&quot;, &quot;Sus Scub Aware Campaign&quot;, &quot;Sus Scub Aware Instructor&quot;, &quot;Sus Scub Shark Conservation&quot;, &quot;Dive Against Debris Speciality&quot;];
  
  module.exports = db;
  </code></pre>