Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thesimons's avatar

Cannot redeclare class XXX (previously declared in

Hello,

I have a problem with a migration. Laravel keeps saying that I can't run this migration because it looks like there's another class with the same name already declared. But it's not true.

Little background: I made a mistake to create the migration with a standard name, ran it and then renamed it. Understood my error I did a migrate:reset and then deleted manually emptied the database, being a test environment.

Here the full code shown in VSC (I just changed the project name.

and here the content of the migration

<?php

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

class ChangeStatusEnumToStringInSubscriptionsTable extends Migration
{
    public function up()
    {
        // Ensure DBAL is installed: composer require doctrine/dbal
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->string('status')->default('pending')->change();
        });
    }

    public function down()
    {
        DB::statement("ALTER TABLE subscriptions MODIFY COLUMN status ENUM('active', 'inactive') NOT NULL DEFAULT 'inactive'");
    }
}

I really can't understand what's wrong I'm doing. I have checked for hidden files, cleaned git cache ... whatever.

Any idea?

Thanks Simon

1 like
3 replies
thesimons's avatar

Changing

class ChangeStatusEnumToStringInSubscriptionsTable extends Migration

with

return new class extends Migration

made the trick. But I'm still curious about the nature of the error above.

Thanks Simon

Please or to participate in this conversation.