Sequelize: column cannot be null even if value is informed
<p>I have the following migration in my app:</p>

<pre><code>module.exports = {
  up(queryInterface, Sequelize) {
    return queryInterface.createTable(
      'question_options',
      {
        id: {
          type: Sequelize.INTEGER,
          primaryKey: true,
          autoIncrement: true,
        },
        question_id: {
          type: Sequelize.INTEGER,
          allowNull: false,
          references: {
            model: 'questions',
            key: 'id',
          },
          onDelete: 'cascade',
        },
        option_id: {
          type: Sequelize.INTEGER,
          allowNull: false,
          references: {
            model: 'options',
            key: 'id',
          },
          onDelete: 'cascade',
        },
      }
    );
  },

  down(queryInterface) {
    return queryInterface.dropTable('question_options');
  },
};
</code></pre>

<p>And the corresponding model:</p>

<pre><code>module.exports = (sequelize, DataTypes) =&gt; {
  const QuestionOption = sequelize.define('QuestionOption', {
    questionId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'question_id',
    },
    optionId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'option_id',
    },
  }, {
    tableName: 'question_options',
    timestamps: false,
    underscored: true,

    createAssociations: (models) =&gt; {
      QuestionOption.belongsTo(models.Option, {
        foreignKey: 'option_id',
      });

      QuestionOption.belongsTo(models.Question, {
        foreignKey: 'question_id',
      });
    },
  });

  return QuestionOption;
};
</code></pre>

<p>When I try to create the object in the database, I get the following error:</p>

<p><code>SequelizeDatabaseError: ER_BAD_NULL_ERROR: Column 'question_id' cannot be null</code></p>

<pre><code>sql: 'INSERT INTO `question_options` (`question_id`,`option_id`) VALUES (NULL,1);' },
</code></pre>

<p>This is the code:</p>

<pre><code>function createQuestionOptions() {
  return models.QuestionOption.create({
    optionId: objects.option.id,
    questionId: objects.question.id,
  });
}
</code></pre>

<p>The only way I could make it work is using both snake case and camel case property names:</p>

<pre><code>function createQuestionOptions() {
  return models.QuestionOption.create({
    optionId: objects.option.id,
    option_id: objects.option.id,
    questionId: objects.question.id,
    question_id: objects.question.id,
  });
}
</code></pre>

<p>How can I fix it?</p>