Sequelize ignores values in create function

Viewed 38

Problem

Trying to create an instance of my model results in this error:
SequelizeDatabaseError: null value in column "player_id" violates not-null constraint

Information

My model is defined like this:
const PlayerTournament = sequelize.define("player_tournament_data", {
  rebuys: INTEGER,
  position: INTEGER,
});

PlayerTournament.associate = () => {
  PlayerTournament.belongsTo(Player, { foreignKey: "player_id" });
  PlayerTournament.belongsTo(Tournament, { foreignKey: "tournament_id" });
};

PlayerTournament.removeAttribute("id");

And the call is done here:

await sequelize.transaction(async ta => {
    try {
      const tournament = await Tournament.create({}, { transaction: ta });


      const promises = players.map(player => {
        const playerID = getPlayerID(player);

        return PlayerTournament.create(
          { player_id: playerID, tournament_id: tournament.id },
          { transaction: ta }
        );
      });

      return await Promise.all(promises);
    } catch (error) {
      throw new Error(error);
    }
  });

But the resulting query looks like:

INSERT INTO "player_tournament_data" DEFAULT VALUES RETURNING "rebuys","position"; 

Thoughts

So basically what happens is that *sequelize* just ignores the values I pass into the function. When I console log the values, I can see that they are here and have the proper format. So did I go somewhere wrong in the definition or is there something else I am not aware of?
0 Answers
Related