-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Added dropColumnsIfExists
, dropColumnIfExists
and dropForeignIfExists
#53305
Conversation
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 dropForeignIfExists
dropColumnsIfExists
, 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
dropColumnsIfExists
method inBuilder
anddropColumnIfExists
/dropForeignIfExists
inBlueprint
.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
dropColumnIfExists
functionality 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!