title: Sequelize 6 import models from file
body: <p>I would like to know how can I import the models from file with Sequelize 6 ?</p>
  <p>It works with     &quot;sequelize&quot;: &quot;^5.22.0&quot;,
  &quot;sequelize-cli&quot;: &quot;^5.5.1&quot;, but I have an error with Sequelize 6.</p>
  <p>Currently, I have this :</p>
  <blockquote>
  <p>database/setup/databaseConnection.js</p>
  </blockquote>
  <pre><code>// Imports
  import { Sequelize } from &quot;sequelize&quot;
  
  const connection = new Sequelize(
      process.env.DATABASE_NAME,
      process.env.DATABASE_USER,
      process.env.DATABASE_PASSWORD,
      {
          host: process.env.DATABASE_URL,
          port: process.env.DATABASE_PORT,
          dialect: &quot;mysql&quot;,
          logging: false,
          define: {
              // prevent sequelize from pluralizing table names
              freezeTableName: true,
          },
      }
  )
  
  // Test connection
  console.info(&quot;SETUP - Connecting database...&quot;)
  
  connection
      .authenticate()
      .then(() =&gt; {
          console.info(&quot;INFO - Database connected.&quot;)
      })
      .catch((err) =&gt; {
          console.error(&quot;ERROR - Unable to connect to the database:&quot;, err)
      })
  
  export { connection as default }
  </code></pre>
  <blockquote>
  <p>database/models/index.js</p>
  </blockquote>
  <pre><code>// Imports
  import Sequelize from &quot;sequelize&quot;
  
  // App Imports
  import connection from &quot;../setup/databaseConnection&quot;
  
  const models = {
      Language: connection.import(&quot;./language&quot;),
  }
  
  Object.keys(models).forEach((modelName) =&gt; {
      if (&quot;associate&quot; in models[modelName]) {
          models[modelName].associate(models)
      }
  })
  
  models.sequelize = connection
  models.Sequelize = Sequelize
  
  export { models as default }
  </code></pre>
  <blockquote>
  <p>database/models/language.js</p>
  </blockquote>
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
      const Language = sequelize.define(
          &quot;language&quot;,
          {
              /* id       : {
           primaryKey: true,
           type      : DataTypes.INTEGER
           }, */
              name: {
                  type: DataTypes.STRING,
              },
              code: {
                  type: DataTypes.STRING,
              },
              is_active: {
                  type: DataTypes.BOOLEAN,
              },
          },
          {}
      )
      Language.associate = function (models) {
          // Language has Many Bucket
          models.Language.hasMany(models.Bucket, {
              foreignKey: &quot;id&quot;,
          })
      }
      return Language
  }
  </code></pre>
  <p>But I have this error :</p>
  <pre><code>formation-api/database/models/index.js:17
    Language: _databaseConnection[&quot;default&quot;][&quot;import&quot;](&quot;./language&quot;)
                                                      ^
  
  TypeError: _databaseConnection.default.import is not a function
      at Object.&lt;anonymous&gt; (/Users/jeremiechazelle/Sites/api/database/models/index.js:8:15)
      at Module._compile (internal/modules/cjs/loader.js:1147:30)
      at Module._compile (/Users/jeremiechazelle/Sites/api/node_modules/pirates/lib/index.js:99:24)
      at Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
      at Object.newLoader [as .js] (/Users/jeremiechazelle/Sites/api/node_modules/pirates/lib/index.js:104:7)
      at Module.load (internal/modules/cjs/loader.js:996:32)
      at Function.Module._load (internal/modules/cjs/loader.js:896:14)
      at Module.require (internal/modules/cjs/loader.js:1036:19)
      at require (internal/modules/cjs/helpers.js:72:18)
      at Object.&lt;anonymous&gt; (/Users/jeremiechazelle/Sites/api/resolvers/Queries/User.js:2:1)
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  <p>I use :
  &quot;sequelize&quot;: &quot;^6.1.0&quot;,
  &quot;sequelize-cli&quot;: &quot;^6.0.0&quot;</p>