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

前端 未结 5 587
北海茫月
北海茫月 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:03

    The key (for me) to solving this was to make sure that the $table->dropForeign() command was being passed the right relationship name, not necessarily the column name. You do not want to pass the column name, as would be much more intuitive IMHO.

    What worked for me was:

    $table->dropForeign('local_table_foreign_id_foreign');
    $table->column('foreign_id');
    

    So the string I passed to dropForeign() that worked for me was in the format of:

    [local table]_[foreign key field]_foreign

    If you have access to a tool like Sequel Pro or Navicat, being able to visualize those will be very helpful.

提交回复
热议问题