[11.x] Added dropColumnsIfExists, dropColumnIfExists and dropForeignIfExists#53305
[11.x] Added dropColumnsIfExists, dropColumnIfExists and dropForeignIfExists#53305taylorotwell merged 9 commits intolaravel:11.xfrom
dropColumnsIfExists, dropColumnIfExists and dropForeignIfExists#53305Conversation
|
This won't work on foreign keys, you will need to delete the constraint first |
Is the same behaviour as |
Thanks! Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
|
yes, except that i can drop the foreign key before the column, |
Done, also added |
dropColumnsIfExists, dropColumnIfExists and dropForeignIfExists
|
Awesome @eusonlito 👌 |
dropColumnsIfExists, dropColumnIfExists and dropForeignIfExistsdropColumnsIfExists, dropColumnIfExists and dropForeignIfExists
|
❤️ |
|
Seems I'm a bit late here! You can't call Solution: use |
|
@hafezdivandari Thank you for your review. Could you open a PR here to fix this issue? |
|
@eusonlito sure. |
This PR introduces the
dropColumnsIfExistsmethod inBuilderanddropColumnIfExists/dropForeignIfExistsinBlueprint.These methods add a convenient way to safely drop columns from a table if they exist, preventing errors when the specified columns are absent.
While I am not entirely sure how to approach creating tests for this functionality, I have tested it extensively in my code with different migration scenarios. For example, I've tested it with columns that are present and others that are not, and in every case, no errors were thrown.
Here’s how the new methods can be used in migrations:
Our team uses a shared database across multiple applications, which requires us to frequently modify the database schema. The
dropColumnIfExistsfunctionality is essential for our workflow as it ensures that migrations run smoothly without being interrupted by missing columns. This enhancement could also be beneficial to others who work in environments where Laravel does not have complete control over the database schema, providing a more resilient and error-proof migration process.Any feedback would be welcome.
Thanks!