[英]Laravel migrate creating table with more than one primary key
我發出命令:
php artisan generate:scaffold order --fields="customer_id:integer(11), order_date:date, notes:text”
當它開始遷移時,它以錯誤結束:
General error: 1 table "orders" has more than one primary key (SQL: create table "orders" ("id" integer not null primary key autoincrement, "customer_id" integer not null primary key autoincrement, "order_date" date not null, "notes" text not null))
有一個 Customer 模型和相應的表,我試圖在架構中使用customer_id
來引用它。 但是,它不應該是orders
表的主鍵。
這是阻止遷移運行的up()
代碼:
Schema::create('orders', function(Blueprint $table)
{
$table->increments('id');
$table->integer('customer_id', 11);
$table->date('order_date');
$table->text('notes');
$table->timestamps();
});
我如何讓這個工作?
問題是您將函數->integer()
與第二個參數一起使用。 根據文檔,第二個參數需要一個布爾值來設置自動增量與否: bool $autoIncrement = false
)。
嘗試這個:
Schema::create('orders', function(Blueprint $table)
{
$table->increments('id');
$table->integer('customer_id');
$table->date('order_date');
$table->text('notes');
$table->timestamps();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.