search

Home  >  Q&A  >  body text

Duplicate constraint error when using laravelsyncWithPivotValue method

I have the following table (MySQL):

This line of code in my asset model (mainly called by asynchronous jobs):

$this->sites()->syncWithPivotValues($sites, ['is_current_site' => true]);

My problem is that when I do this line I keep getting duplicate constraint errors and I don't understand why. Any ideas?

P粉884667022P粉884667022446 days ago511

reply all(1)I'll reply

  • P粉068486220

    P粉0684862202023-09-15 00:34:14

    The problem I am facing is the concurrency issue between jobs.

    I used the WithoutOverlapping middleware (https://laravel.com /docs/9.x/queues#preventing-job-overlaps) to prevent concurrency problems on my jobs, and the effect is very good .

    reply
    0
  • Cancelreply