nexxai
200
2
Laravel

Can you remove a foreign key reference without dropping the column entirely?

Posted 1 year ago by nexxai

Say I used these lines in a migration:

$table->integer('dog_id')->unsigned();
$table->foreign('dog_id')->references('id')->on('dogs');

Now say later in development, I realized that I should have generalized better and so what I want to do is rename the "dogs" table to "pets". I rename the table to "pets" and rename columns to "pet_id" and that all works, but the foreign key relationship is still pointing to the "dogs" table. Do I just do:

$table->dropForeign('dog_id');

and call it a day? If that actually drops all the data in that column then that's bad. Or is there something else I need to do too?

Thanks

Please sign in or create an account to participate in this conversation.