2016-09-15 118 views
4

here提到的,我們可以在遷移
製作的關係時,用這個詞cascade,但我不知道他們沒有說其他動作時,deletingupdating外鍵什麼

,所以我不知道是否有這樣的東西還是不:
其他行動5.2

$table->foreign('user_id') 
    ->references('id')->on('users') 
    ->onDelete('set null'); 
    //->onDelete('set_null'); 
    //->onDelete('setNull'); 

或同一件事onUpdateno action就像phpMyAdmin

enter image description here


感謝

回答

6

你可以做phpmyadmin提到這種方式的所有選項:

$table->...->onDelete('CASCADE'); 
$table->...->onDelete('SET NULL'); 
$table->...->onDelete('RESTRICT'); 

// do not call the onDelete() method if you want the NO ACTION option. 

你必須確保你設置的外鍵字段爲空的:

$table->...->unsigned()->nullable();