Skip to content

Adding a field and updating in the same migration #55679

Closed
@Zwartpet

Description

@Zwartpet

Laravel Version

12.13.0

PHP Version

8.3

Database Driver & Version

sqlite

Description

Since 12.12.0 we can't add a field and update the field in the same migration anymore. Running into this issue when running pest which runs the migrations on an sqlite database.

SQLSTATE[HY000]: General error: 1 no such column: has_non_mappable_coverage (Connection: sqlite, SQL: update "policies" set "has_non_mappable_coverage" = 0, "updated_at" = 2025-05-08 13:42:04 where "has_non_mappable_coverage" is null and "policies"."deleted_at" is null)

Does still work with 12.11.1

<?php

use App\Models\Policy;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::table('policies', function (Blueprint $table) {
            $table->boolean('has_non_mappable_coverage')->nullable()->default(0);
        });

        Policy::where('has_non_mappable_coverage', null)->update(['has_non_mappable_coverage' => false]);
    }

    public function down()
    {
        ....
    }
};

Steps To Reproduce

Updating a field in the same migration where it's created and running the migrations or pest.

Caused by making the resolver static in: #55607

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions