SergiX44's avatar

Error with failed jobs on Lumen

When a job fails on Lumen, I've got a SQL error on inserting the failed jobs table in logs:

Field 'uuid' doesn't have a default value (SQL: insert into `failed_jobs` (`connection`, `queue`, `payload`, `exception`, `failed_at`) values (...)

From the console (I'm forcing the job fail with an exception here for show the issue):

[2021-01-09 14:31:47][fE95MXC6bKOJdgOctLFo43EzoaOXST6N] Processing: App\Jobs\MyJob
[2021-01-09 14:31:47][fE95MXC6bKOJdgOctLFo43EzoaOXST6N] Failed:     App\Jobs\MyJob

This is the migration generated by lumen:

Schema::create('failed_jobs', function (Blueprint $table) {
            $table->id();
            $table->string('uuid')->unique();
            $table->text('connection');
            $table->text('queue');
            $table->longText('payload');
            $table->longText('exception');
            $table->timestamp('failed_at')->useCurrent();
        });

I'm using the latest version of Lumen, with redis as queue broker. I need to put something to generate the uuid? Or I should remove the uuid column?

Thanks in advance!

0 likes
3 replies
Tray2's avatar

You need to pass the jobs uuid to the method doing the insert into the failed jobs table,

spyworld's avatar

I think schema isn't making sense. id should be unique. UUID is a string shouldn't be unique in this schema.

https://laravel.com/docs/8.x/queues

According to documentation, id is part of uuid.

This should be,

$table->uuid('id')->unique();

Please or to participate in this conversation.