Did you check that it exists? Maybe it was removed in some of the previous migrations?
Apr 7, 2020
7
Level 1
Can't drop foreign keys
I have some data in Page and PageCategory. I am trying to move data around into new tables, so they need to go.
In the original migration:
Schema::table('pages', function (Blueprint $table) {
$table->bigInteger('page_category_id')->nullable()->unsigned();
});
Schema::table('pages', function (Blueprint $table) {
$table->foreign('page_category_id')->references('id')->on('page_categories');
});
Trying to remove the 'page_category_id' from my 'pages' table:
Schema::table('pages', function (Blueprint $table) {
$table->dropForeign(['page_category_id']);
});
Schema::table('pages', function (Blueprint $table) {
$table->dropColumn('page_category_id');
});
This just gives me an error:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'pages_page_category_id_foreign'; check that column/key exists (SQL: alter table `pages` drop foreign key `pages_page_category_id_foreign`)
Not sure what I'm doing wrong. Even when I put the above Schema statements between:
Schema::disableForeignKeyConstraints();
[...]
Schema::enableForeignKeyConstraints();
It still gives the same error.
Laravel 6.x btw.
Level 61
Please or to participate in this conversation.