我想为我的项目进行新的迁移,这种迁移被称为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
那么如何解决呢?
$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');
});