My project is experiencing a peculiar issue. I am using laravel 5.4 with MySQL. I am inserting multiple records (30,60, etc) and seldom it inserts duplicate records. Eg- while creating records from 1/1/2018 to 30/1/2018 ie it should be inserting 30 records. Sometimes it does insert 30 records, but often it inserts more than that. There might be few duplicate entries like on 5,6,7 then 21,22,23,24 etc. I checked on Github regarding this issue, and few people did face this issue, few said this is because of "Race Conditions". It is really because of Race conditions? Why does this duplication occur? And is there any way to prevent it, I would prefer not locking my Database because multiple people might be inserting at the same time. Suggestions appreciated.
`$sdata = [
'tenant_id' => Helper::getTenantID(),
'branch_id' => Helper::getBranchID(),
'user_id' => Helper::getUserID(),
'service_request_id' => $serviceRequestID,
'amount' => $netRate,
'notes' => $notes,
'status' => 'Pending',
];
Schedule::updateOrCreate($sdata);`