Dropping column with foreign key Laravel error: General error: 1025 Error on rename

前端 未结 5 586
北海茫月
北海茫月 2020-12-13 05:39

I\'ve created a table using migration like this:

public function up()
{
    Schema::create(\'despatch_discrepancies\',  function($table) {
        $table->         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 06:14

    It turns out; when you create a foreign key like this:

    $table->integer('pick_detail_id')->unsigned();
    $table->foreign('pick_detail_id')->references('id')->on('pick_details');
    

    Laravel uniquely names the foreign key reference like this:

    ___foreign
    despatch_discrepancies_pick_detail_id_foreign (in my case)
    

    Therefore, when you want to drop a column with foreign key reference, you have to do it like this:

    $table->dropForeign('despatch_discrepancies_pick_detail_id_foreign');
    $table->dropColumn('pick_detail_id');
    

    Update:

    Laravel 4.2+ introduces a new naming convention:

    __foreign
    

提交回复
热议问题