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
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.
Symfony\Component\ErrorHandler\Error\FatalError
Cannot redeclare class ChangeStatusEnumToStringInSubscriptionsTable (previously declared in /Users/FOO/Documents/sites/FOO/database/migrations/0002_00001_change_status_enum_to_string_in_subscriptions_table.php:8)
at database/migrations/0002_00001_change_status_enum_to_string_in_subscriptions_table.php:8
4▕ use Illuminate\Database\Schema\Blueprint;
5▕ use Illuminate\Support\Facades\Schema;
6▕ use Illuminate\Support\Facades\DB;
7▕
➜ 8▕ class ChangeStatusEnumToStringInSubscriptionsTable extends Migration
9▕ {
10▕ public function up()
11▕ {
12▕ // Ensure DBAL is installed: composer require doctrine/dbal
Whoops\Exception\ErrorException
Cannot redeclare class ChangeStatusEnumToStringInSubscriptionsTable (previously declared in /Users/FOO/Documents/sites/FOO/database/migrations/0002_00001_change_status_enum_to_string_in_subscriptions_table.php:8)
at database/migrations/0002_00001_change_status_enum_to_string_in_subscriptions_table.php:8
4▕ use Illuminate\Database\Schema\Blueprint;
5▕ use Illuminate\Support\Facades\Schema;
6▕ use Illuminate\Support\Facades\DB;
7▕
➜ 8▕ class ChangeStatusEnumToStringInSubscriptionsTable extends Migration
9▕ {
10▕ public function up()
11▕ {
12▕ // Ensure DBAL is installed: composer require doctrine/dbal
+1 vendor frames
2 [internal]:0
Whoops\Run::handleShutdown()
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
Please or to participate in this conversation.