4

I have to import rows from a .csv, and put them in my database (chunks of 500). To do this i'm using the sequelize bulkCreate functionality.

I have a field called address which is required (not nullable). If one of the rows fails to insert (because the row in my csv doesn't have an address) the entire batch fails. what I want to achieve is that bulkCreate attempts to insert the lines, and ignores the ones which fail.

Anyway to achieve this? Here's my current code if it helps

export const createEnterprise = async (rows: any[]) => {
  try {
    // Create enterprise record
    await models.enterprise.bulkCreate(rows);
  } catch (err) {
    console.log(err);
    throw err
  }
};
Nicolas
  • 4,526
  • 17
  • 50
  • 87
  • There is a non-null constraint on the `address` column of the `Enterprise` table. Maybe you can filter the rows use the application code firstly. Then, you can insert the cleaned and satisfied the non-null constraint data. – Lin Du Feb 14 '20 at 07:15

0 Answers0