I'm trying to drop the foreign key to an existing table using migration but it throws an error as "Syntax error or access violation:1091 cant DROP consultant_id :check that column/key exists". Can you please help with it?
Asked
Active
Viewed 617 times
0
-
it will help you : https://stackoverflow.com/a/51861737/4934273 – Md. Abutaleb Nov 11 '19 at 07:04
-
1Show your table schema and the code that tries to drop the foreign key. – Styx Nov 11 '19 at 07:11
2 Answers
1
First of all, you have to drop Foreign constraint.
public function up() {
Schema::table('table_name', function (Blueprint $table) {
$table->dropForeign('table_name_consultant_id_foreign');
$table->dropColumn('consultant_id');
});
}

Prashant Morem
- 46
- 3
0
disable foreign key checks before you drop the table then enable them
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Schema::dropIfExists('your_choice_table');
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

albus_severus
- 3,626
- 1
- 13
- 25