title: table association not created One-To-Many sequelize node
body: <p>I was creating associations for my database. But she did not create all the associations, for example, she did not link the contracts with the payroll. I tried the options from the database, but they did not help. Tell me what I can try to do and what I'm doing wrong?</p>
  <p>Create association</p>
  <pre><code>db.Contracts.hasMany(db.Payrolls, {
          foreignKey: {
              name: 'contract_id',
              sourceKey: 'id',
          }
      })
      db.Payrolls.belongsTo(db.Contracts, {
          foreignKey: {
              name: 'contract_id',
              targetKey: 'id',
          }
      })
  </code></pre>
  <p>Create Contracts</p>
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
      const Contracts = sequelize.define(&quot;Contracts&quot;, {
          id: {
              type: DataTypes.STRING,
              allowNull: false,
              primaryKey: true,
              autoIncrement: false
          },
          month_pay: {
              type: DataTypes.INTEGER, 
              allowNull: false
          }
      }, { timestamps: false });
      
      return Contracts;
  };
  </code></pre>
  <p>Create Payrolls</p>
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
      const Payrolls = sequelize.define(&quot;Payrolls&quot;, {
          id: {
              type: DataTypes.INTEGER,
              primaryKey: true,
              allowNull: false,
              autoIncrement: true
          },
          pay_date: {
              type: DataTypes.DATE,
              allowNull: false,
          },
          amount: {
              type: DataTypes.INTEGER, 
              allowNull: false
          }
      }, { timestamps: false });
  
      return Payrolls
  };
  </code></pre>
  <p><a href="https://i.stack.imgur.com/r73vx.png" rel="nofollow noreferrer">App: DbShema</a></p>
  <p>e.g. working associations:</p>
  <pre><code>module.exports = (db) =&gt; {
  
      //#region One-To-Many Contracts-&gt;Courses
      db.Courses.hasMany(db.Contracts, {
          foreignKey: {
              name: 'course_name',
              sourceKey: 'name',
              primaryKey: true,
          }
      })
      db.Contracts.belongsTo(db.Courses, {
          foreignKey: {
              name: 'course_name',
              targetKey: 'name',
              primaryKey: true,
          }
      })
      //#endregion
  
      //#region One-To-Many Contracts-&gt;Pupils
      db.Pupils.hasMany(db.Contracts, {
          foreignKey: {
              name: 'pupil_id',
              sourceKey: 'id',
              primaryKey: true,
          }
      })
      db.Contracts.belongsTo(db.Pupils, {
          foreignKey: {
              name: 'pupil_id',
              targetKey: 'id',
              primaryKey: true,
          }
      })
      //#endregion
      
      //#region One-To-Many Payrolls-&gt;Contracts
      db.Contracts.hasMany(db.Payrolls, {
          foreignKey: {
              name: 'contract_id',
              sourceKey: 'id',
              
          }
      })
      db.Payrolls.belongsTo(db.Contracts, {
          foreignKey: {
              name: 'contract_id',
              targetKey: 'id',
              
          }
      })
      //#endregion
      
      return db
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Oh9mM.png" rel="nofollow noreferrer">Visualisation</a></p>
  <h6><a href="https://drive.google.com/drive/folders/1_s5u6MW8xfhct3kayk3RKlqxCyZ9GuCo?usp=sharing" rel="nofollow noreferrer">if you need the project itself (its part of the database)</a></h6>