Laravel :: Best way to update a foreign key

后端 未结 4 1583
予麋鹿
予麋鹿 2020-12-05 18:06

I have this migration file

Schema::create(\'table_one\', function(Blueprint $table) 
{ 
    $table->increments(\'id\'); 
    $table->string(\'name\');          


        
4条回答
  •  佛祖请我去吃肉
    2020-12-05 18:42

    Christopher K. is right, at the Laravel docs says:

    To drop a foreign key, you may use the dropForeign method. Foreign key constraints use the same naming convention as indexes. So, we will concatenate the table name and the columns in the constraint then suffix the name with "_foreign":

    $table->dropForeign('posts_user_id_foreign'); 
    

    Or, you may pass an array value which will automatically use the conventional constraint name when dropping:

    $table->dropForeign(['user_id']);
    

    https://laravel.com/docs/5.7/migrations#foreign-key-constraints

提交回复
热议问题