Laravel 8: Unknown column ‘uuid’ on failed_jobs table

Laravel 8: Unknown column ‘uuid’ on failed_jobs table

I recently upgraded a project of mine to Laravel 8 (from Laravel 7).
Everything seemed to go really well with just a few snags here and there. I then noticed however a number of errors were getting logged when the system tried to record failed jobs.
I turned out that Laravel 8 introduces an additional column in to the failed_jobs table that causes an error similar to the following if its not present:
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘uuid’ in ‘field list’ (SQL: insert into `failed_jobs` (`uuid`, `connection`, `queue`, `payload`, `exception`, `failed_at`)

To get around this, I could have added the column but instead I updated the migration for failed_jobs (good housekeeping for the future) and then re-created the failed jobs table using that (safe as it has no dependancies).

Laravel 8 failed_jobs Table Migration

The first thing you’ll need to know is what the Laravel 8 failed_jobs migration looks like, I had to deploy a new Laravel 8 to find out so figured I’d paste it here is full for anyone that needs it.

In summary, you just need to add the line that generates the uuid column:
$table->string(‘uuid’)->unique();

The full migration is:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFailedJobsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        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();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('failed_jobs');
    }
}

I then deleted the existing failed_jobs table in my database via PHPMYADMIN, obviously this could be different depending on how you have your project hosted:

Delete the migrations table entry

Important: you must also delete the migration from the migrations table, otherwise you will get a “Nothing to migrate” message when you try to run the migration for the failed_jobs table.

Again I used PHPMYADMIN, opened up the migrations table and delete the row listing my migration:

Run the migration to create the the failed_jobs table

Once you’ve updated the laravel failed_jobs migration, delete the existing failed_jobs table and removed the old entry from the migrations table, you can run the updated migration.  To do this for only the failed_jobs specific migration, use the following command, updating the migration filename:

php artisan migrate --path=/database/migrations/2021_02_19_000000_create_failed_jobs_table.php

That’s it – once the migration has run, you now have a new failed_jobs table compatible with Laravel 8!

Bob McKay

About Bob McKay

Bob is a Founder of Seguro Ltd, a full time father and husband, part-time tinkerer-with-wires, coder, Muay Thai practitioner, builder and cook. Big fan of equality, tolerance and co-existence.

Disclosure Policy

3 comments on «Laravel 8: Unknown column ‘uuid’ on failed_jobs table»

  1. Eimantas says:

    Hey,

    It is not the best practice to amend existing migrations, so what I would suggest is just simply create a new migration with artisan: php artisan make:migration add_uuid_field_to_failed_jobs_table and then have the following contents:

    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;

    Schema::table(‘failed_jobs’, function (Blueprint $table) {
    $table->string(‘uuid’)->after(‘id’)->nullable()->unique();
    });

    Please note that it has a nullable field because there may be already existing rows in the table and if you are not using database-uuids for queue failed.driver, it will throw errors as well.

    More info at https://laravel.com/docs/8.x/upgrade#failed-jobs-table-batch-support

    1. Bob McKay says:

      There he is! Funny I mentioned you in an article I wrote yesterday (done worry it was all good). How’s it going buddy? Thanks for the tips here. Yeah I know its not best practice to amend migrations but I prefer to keep mine clean where possible rather than having loads of migrations for amendments – probably a habit I need to get out of. Take a look at my Laravel learning project: still lots to learn but I needed a project so here it: https://phishdom.com/. Frustratingly, just as I finished, Laravel 8 was released which changed up the authentication options a lot so I need to revisit that (and I need to build and API too). Loads of things to do but I’m just about ready to start asking for beta testers.

  2. Stefan says:

    Hi, thank for this article. What weird is, is that all our apps are running on 8.51 and all instead of the new one dont have that col uuid but failed_jobs are written…. weird.. i hate updates 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.