Warm tip: This article is reproduced from serverfault.com, please click

php-函数Illuminate \ Database \ Schema \ Blueprint :: bigIncrements()的参数太少,已传递0

(php - Too few arguments to function Illuminate\Database\Schema\Blueprint::bigIncrements(), 0 passed)

发布于 2020-11-30 06:13:11

我想为我的项目进行新的迁移,这种迁移被称为create_active_code.php并且如下所示:

public function up()
{
    Schema::create('active_code', function (Blueprint $table) {
        $table->bigIncrements();
        $table->unsignedBigInteger('user_id');
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->integer('code');
        $table->unique(['user_id', 'code']);
        $table->timestamps('expired_at');
    });
}

但是,一旦运行此迁移,就会出现此错误:

ArgumentCountError 函数Illuminate \ Database \ Schema \ Blueprint :: bigIncrements()的参数太少,第17行的F:\ xampp \ htdocs \ frameworks \ rooket2 \ database \ migrations \ 2020_11_30_055654_create_active_code.php中传递了0,并且恰好期望1

那么如何解决呢?

Questioner
fojbiu
Viewed
0
POOYAA 2020-11-30 15:28:06

$table->bigIncrements();应该是id()并且外键应该与id属于同一类型。

Schema::create('active_code', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->references('id')->on('user')->onDelete('cascade');
                $table->integer('code');
                $table->unique(['user_id', 'code']);
                $table->timestamp('expired_at');
            });