Last active
May 9, 2021 14:51
-
-
Save tangorri/8556762 to your computer and use it in GitHub Desktop.
got this error [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1553 Cannot drop index 'customers_professio n_id_foreign': needed in a foreign key constraint (SQL: alter table `custom ers` drop `profession_id`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
class AddProfessionColumnToCustomersTable extends Migration { | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::table('customers', function($table) | |
{ | |
$table->integer('profession_id')->unsigned(); | |
$table->foreign('profession_id')->references('id')->on('professions'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::table('customers', function(Blueprint $table){ | |
$table->dropColumn('profession_id'); | |
$table->dropForeign('customers_profession_id_foreign'); | |
}); | |
} | |
} |
hadavand thanks
You should write "down" method with the following order:
$table->dropForeign('customers_profession_id_foreign');
$table->dropColumn('profession_id');
it helps me thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should write "down" method with the following order:
$table->dropForeign('customers_profession_id_foreign');
$table->dropColumn('profession_id');