I am trying to insert multiple rows into my database using Sequelize, but the for loop is stuck due to some violation of restrictions.
let dataset = [
["2016-01-01","987"],
["2016-01-02","987"],
["2016-01-03","987"],
["2016-01-04","987"],
["2016-01-05","987"],
["2016-01-06","987"],
["2016-01-07","987"],
...
];
for(let row of dataset) {
model.findOrCreate({
where: {date_prc: row[0]},
defaults: {value: row[1]}
});
}
When I look at the SQL log, it checks to see if the date has already been inserted, and if it is not trying to insert a row. But in some cases, instead of inserting the missing date string, it inserts the next date.
For example, in the log I see:
select 2016-01-03 // this one is missing
select 2016-01-04 // this one is not missing
insert 2016-01-04 // it is inserting 2016-01-04 instead of 2016-01-03
source
share