Support the ongoing development of Laravel.io →
Database
Last updated 3 months ago.
0

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');
    });
Last updated 3 months ago.
0

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.

Last updated 3 months ago.
0

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?

Last updated 7 years ago.
0

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.

0

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']);
});
0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.