【问题标题】:Cannot declare class because the name is already in use?无法声明类,因为该名称已在使用中?
【发布时间】:2021-08-17 04:34:12
【问题描述】:

我正在使用带有 Spark 的 Laravel 8。我正在设置 Stripe(通过文档)并遇到了我无法理解的错误。

在终端中,尝试php artisan migrate 我收到以下错误:无法声明类 CreateReceiptsTable,因为该名称已在使用中。

我尝试了php artisan config:cachecomposer dump_autoload,但运气不佳。

这是一个全新的安装,所以我不明白为什么会出现这个错误。

编辑:我尝试过的事情 - php artisan migrate:fresh php artisan migrate:rollback 但没有解决问题。

希望有人能提供帮助。

创建收据表:


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

class CreateReceiptsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('receipts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('billable_id');
            $table->string('billable_type');
            $table->unsignedBigInteger('paddle_subscription_id')->nullable()->index();
            $table->string('checkout_id');
            $table->string('order_id')->unique();
            $table->string('amount');
            $table->string('tax');
            $table->string('currency', 3);
            $table->integer('quantity');
            $table->string('receipt_url')->unique();
            $table->timestamp('paid_at');
            $table->timestamps();

            $table->index(['billable_id', 'billable_type']);
        });
    }

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

日志详情

"} 
[2021-05-29 12:10:04] local.ERROR: Cannot declare class CreateReceiptsTable, because the name is already in use {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Cannot declare class CreateReceiptsTable, because the name is already in use at /Users/dad/Desktop/projects/Sumpaper/vendor/laravel/spark-stripe/database/migrations/2019_06_03_000003_create_receipts_table.php:7)
[stacktrace]
#0 {main}
"} 

【问题讨论】:

标签: laravel laravel-spark


【解决方案1】:

我也遇到了同样的问题,就是迁移文件名和迁移类名不一样。 通过将文件名重命名为原始文件名来修复它。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,在尝试不同的事情时,我发现我对同一个表进行了重复迁移,所以我删除了迁移文件夹中的重复表并运行了迁移,现在可以正常工作了。如果您在迁移文件夹中有重复的表,那么它将尝试创建同一个表两次,这就是错误消息所说的。希望对您有所帮助。

    【讨论】:

      【解决方案3】:

      听起来您已经运行了迁移,并且表已经存在。

      如果这是开发环境,请运行 php artisan migrate:fresh 以获取数据库的新副本。不要在生产实例上执行此操作,因为它会擦除所有数据。

      如果是生产,则需要创建新的迁移来对现有表进行更改,而不是编辑现有的迁移。

      【讨论】:

      • 我跑了php artisan migrate:fresh 我得到了同样的错误。我也试过php artisan:rollback nothing 来回滚。
      猜你喜欢
      • 2020-06-21
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多