Laravel 13.42 MigrationFailed: Database Differences

Résumé

Pixel shares a hands-on test of Laravel 13.42’s new MigrationFailed event using a slug migration that fails when duplicate product names create a unique-index conflict. The test compares MySQL 8.4.13, PostgreSQL 17.12, and SQLite 3.53.4, showing why failed migrations can leave partial schema changes that block retries.

DEV Community

I Broke One Laravel Migration on MySQL, PostgreSQL and SQLite. What MigrationFailed in 13.42 Changes

Originally published at hafiz.dev You fix the duplicate data, run php artisan migrate again, and Laravel answers with Duplicate column name 'slug'. The migration failed the first time, so Laravel never recorded it. But half of it ran anyway, and now that half blocks the retry. Laravel 13.42 added a MigrationFailed event for this exact moment (PR #62342, from Jack Bayliss). It fires when a migration throws and carries the exception. The release write-up on Laravel News suggests using it to alert your team before users hit a half-applied schema. So which databases actually leave one behind? I ran the same failing migration on MySQL 8.4.13, PostgreSQL 17.12 and SQLite 3.53.4 (the version bundled with PHP 8.4 on my Mac), all on Laravel 13.42.0. They didn't all leave the same mess behind. The migration that fails halfway It's the classic slug migration. Add a nullable column, backfill it, then add the unique index: public function up(): void
{
Schema::table('products', function (Blueprint $table) {
$table->string('slug')->nullable()->after('name');
});

DB::table('products')->orderBy('id')->each(function ($product) {
    DB::table('products')
        - >where('id', $product->id)
        - >update(['slug' => Str::slug($product->name)]);
});

Schema::table('products', function (Blueprint $table) {
    $table->unique('slug');
});

}
The products table has three rows: Blue Mug, Red Kettle, and a second Blue Mug (two sizes, same name). The backfill writes blue-mug twice, so the index can't be built. That's the failure, on purpose. It's also a realistic one, because a duplicate like this shows up in production data and almost never in a seeded local database. MySQL keeps the column, and the retry fails The first run, with the stack trace trimmed: 2026_11_14_000002_add_slug_to_products_table .. 32.09ms FAIL

Illuminate\Database\UniqueConstraintViolationException

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'blue-mug'
for key 'products.products_slug_unique' (Connection: mysql, ... SQL: alter table
products add unique products_slug_unique(slug))
Then I checked the table and the migrations table: Schema::hasColumn('products', 'slug');
DB::table('products')->orderBy('id')->pluck('slug');
collect(Schema::getIndexes('products'))->pluck('name');
DB::table('migrations')->where('migration', 'like', '%add_slug%')->exists();
slug column: true
slugs: ["blue-mug","red-kettle","blue-mug"]
indexes: ["primary"]
recorded: false
The column is there. The backfilled slugs are there. The index isn't, and Laravel has no record that any of it happened. So I renamed the second product to Blue Mug Large and ran migrate again: 2026_11_14_000002_add_slug_to_products_table .. 7.97ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'slug'
(Connection: mysql, ... SQL: alter table products add slug varchar(255) null after name)
The data is fixed. The migration still can't run, because its first statement now collides with its own leftovers. From here you drop the column by hand, edit the migration, or insert a fake row into migrations. None of those belong in a deploy. PostgreSQL rolls the whole thing back Same migration, same three rows, same failure on the unique index. The state afterwards: slug column: false
indexes: ["products_pkey"]
recorded: false
No column, no slugs, no record. After the same rename, the retry just worked: 2026_11_14_000002_add_slug_to_products_table .. 12.95ms DONE
It's the behaviour I'd assumed I was getting everywhere. And SQLite? New Laravel apps have used SQLite as the default database since Laravel 11, so plenty of local setups run this exact path. View the interactive component on hafiz.dev slug column: true
slugs: ["blue-mug","red-kettle","blue-mug"]
indexes: ["primary"]
recorded: false
SQLite kept everything MySQL kept. The retry failed the same way too, with dupli...
Laravel 13.42 MigrationFailed: Database Differences
Powered by Readybot.io

Les dernières actus de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …