0
我知道這很容易被這樣實現:laravel 5.4添加索引字段
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->unsignedInteger('gender_id');
$table->date('date_of_birth');
$table->date('active_in_sport');
$table->unsignedInteger('people_type_id');
$table->timestamps();
$table->unique([
'first_name',
'last_name'
]);
$table->index('gender_id');
$table->index('people_type_id');
這樣做的缺點是,Laravel首先創建表,比運行一個alter table
查詢。 因爲這一點,我遇到了一個外鍵錯誤,所以我想將索引添加到create語句中的字段。我怎樣才能做到這一點?
如果您剛剛創建表並且外鍵無法引用它,您將如何遇到外鍵錯誤? – Padarom