Skip to content

Instantly share code, notes, and snippets.

@tangorri
Last active May 9, 2021 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangorri/8556762 to your computer and use it in GitHub Desktop.
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`)
<?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
Copy link

hadavand commented Aug 3, 2015

You should write "down" method with the following order:
$table->dropForeign('customers_profession_id_foreign');
$table->dropColumn('profession_id');

@thomas-tewelde
Copy link

hadavand thanks

@Jnalis
Copy link

Jnalis commented May 9, 2021

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