Laravel Supervisor: Duplicate entry '' for key 'failed_jobs_uuid_unique'

Viewed 1307

I'm using Laravel's Supervisor for queue management, and added the failed_jobs table by using the default commands (php artisan queue:failed-table + migrate).

A job sometimes fails, but the failed_jobs table is never filled because it apparently tries to add a record without a primary key. I have no idea where in Laravel to have it generate a uuid.

I find issues like Duplicate entry '014c3080-3ee3-4198-946c-dfe1d8d858a7' for key 'failed_jobs_uuid_unique', but that has a different cause. My application doesn't even generate a uuid.

3 Answers

The uuid of a Job is generated trough a driver named "database-uuids". This should be configured by default inside your config/queue.php as following (near the end of the file):

'failed' => [
    'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
    'database' => env('DB_CONNECTION', 'mysql'),
    'table' => 'failed_jobs',
],

Unless you have provided another value for QUEUE_FAILED_DRIVER in your .env file, your failed_jobs should be given a uuid by default.

If this does not work, please leave a comment on this answer and I'll try look for another solution.

It seems like Laravel is trying to log the same failed job with the same UUID multiple times. This may happen when two workers pick the same job and both executions fail. The first worker will be able to log the job successfully but the second worker will receive this error because an entry with the same UUID already exists.

check this link for prevent this issue

https://divinglaravel.com/prevent-your-queued-jobs-from-duplicating

Change uuid field nullable at failed_jobs table.

Related