我的表帖子沒有任何限制,我默認Laravel選擇自動增量。它仍然失敗,并顯示“只能在自動增量列上”。移民public function up(){ Schema::create('posts', function (Blueprint $table) { $table->id(); $table->id('user_id')->nullable(); $table->id('admin_id')->nullable(); $table->string('about')->nullable(); $table->decimal('price')->nullable(); $table->string('new_used')->nullable(); $table->string('negotiable')->nullable(); $table->dateTime('expire_date')->nullabe(); $table->timestamps(); });}
2 回答

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
您不能有多個自動遞增列。將外鍵類型更改為unsignedInteger(),它應該可以工作。這通常是我創建 id 列加上兩個外鍵的方式。
$table->increments('id');
$table->unsignedInteger('user_id')->nullable();
$table->unsignedInteger('admin_id')->nullable();
或者,您也可以創建外鍵引用。
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('admin_id')->references('id')->on('users');

守著一只汪
TA貢獻1872條經驗 獲得超4個贊
id
on 方法是Blueprint
一個別名,用于bigIncrements
創建無符號大整數自動增量字段。
因此,該表的遷移中有 3 個自動增量字段,但只能有 1 個。
- 2 回答
- 0 關注
- 149 瀏覽
添加回答
舉報
0/150
提交
取消