Your foreign keys is named table_fields_foreign
. So in your case you would want this:
Schema::table('authors_books', function(Blueprint $table) {
$table->dropForeign('author_books_author_id_foreign');
$table->dropForeign('author_books_book_id_foreign');
});
Thanks for the response. The table is actually 'authors_books', but if I correct that it works fine.
It's also clearly indicated in the documentation, but I just missed it.
http://laravel.com/docs/schema#dropping-indexes
This still seems strange to me though. If Schema creates the foreign key / index, then I would expect it should drop it using the same name. That Schema actually creates an index called 'authors_books_author_id_foreign' when I pass it 'author_id' that's fine, but then I would expect it to maintain that intelligence when dropping it as well.
It don't work to me :(
Here is my code:
\Schema::table('contract', function(Blueprint $table) {
$table->dropForeign('contract_product_id_foreign');
$table->removeColumn('product_id');
});
What is wrong?
Don't use the foreign table in the name, only the current table. It seems they changed the format from last year. Reread the documentation from visualasparagus's link carefully.
I don't know why Laravel does this. It certainly isn't expected behavior from someone new to databases and it's not clearly documented.
In laravel 5.1 (don't know since which version) it's also possible to let laravel create the key name by putting the column(s) into an array, like:
Schema::table('authors_books', function(Blueprint $table) {
$table->dropForeign(['author_id']);
$table->dropForeign(['book_id']);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community