[11.x] Add dropForeign support on SQLiteGrammar (#51318) #51358
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request proposes an enhancement to Laravel's SQLiteGrammar in order to support the drop on foreign keys. It uses the same approach as
doctrine/dbal
which is recreating the table while removing the foreign key constraint and use the logic of the existingcompileChange
method to do so.Motivation
The motivation behind this enhancement is to provide developers the ability to use foreign keys on SQLite and be able to drop them.
Use Cases
In a project that uses SQLite and foreign keys on a column. It is currently not possible to drop a column that has a foreign key constraint on it. Currently if we try to drop the foreign key, we receive the following exception:
This database driver does not support dropping foreign keys
. Therefore, the PR is to provide the ability to drop the foreign key before dropping the column.For example, this migration will add a foreign key on the
user_id
of thesession
table.Then when trying to delete the column
user_id
which has a foreign key with the following migration will throw an exception when using the SQLite Driver.fix #51318