Laravel :: Best way to update a foreign key

后端 未结 4 1585
予麋鹿
予麋鹿 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:19

    Drop the foreign key then add it again and run migrate.

    public function up()
    {
        Schema::table('table_one', function (Blueprint $table) {
            $table->dropForeign(['table_two_id']);
    
            $table->foreign('table_two_id')
                ->references('id')
                ->on('table_two')
                ->onDelete('cascade');
        });
    }
    

提交回复
热议问题