Skip to content
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

[5.7] Add an sqlite config option to enable foreign key constraints #26298

Merged
merged 1 commit into from
Oct 29, 2018
Merged

[5.7] Add an sqlite config option to enable foreign key constraints #26298

merged 1 commit into from
Oct 29, 2018

Conversation

dakira
Copy link
Contributor

@dakira dakira commented Oct 29, 2018

For Sqlite, foreign key constraints need to be explicitly enabled for every database connection. So enabling them in the migrations (as suggestednby the documentation) does not work.

This PR enables the contraints for every connection to an sqlite database that has the config option foreign_key_constraints set to true.

If the option is not set, nothing changes, so no breaking change is introduced.

As foreign key constraints are the default behavior for all other databases I suggest switching this around for the next release and enable foreign keys unless this is set to false.

If this is accepted I'll submit two more PRs for documentation and laravel/laravel.

For Sqlite, foreign key constraints need to be explicitly enabled for
every database connection. So enabling them in the migrations (as suggested
by the documentation) does not work.

This PR enables the contraints for every connection to an sqlite database
that has the config option `foreign_key_constraints` set to `true`.

If the option is not set, nothing changes, so no breaking change is
introduced.

As foreign key constraints are the default behavior for all other databases
I suggest switching this around for the next release and enable foreign
keys unless this is set to `false`.

If this is accepted I'll submit two more PRs for documentation and
laravel/laravel.
@taylorotwell taylorotwell merged commit 56a62cb into laravel:5.7 Oct 29, 2018
@dakira dakira deleted the sqlite-fk-setting branch October 30, 2018 12:14
@GrahamCampbell GrahamCampbell changed the title add an sqlite config option to enable foreign key constraints [5.7] Add an sqlite config option to enable foreign key constraints Oct 30, 2018
gomasy pushed a commit to gomasy/bookshelf that referenced this pull request Oct 31, 2018
This enables the sqlite `foreign_key_constraints` option that was introduced with laravel/framework#26298 for all new installs.

The env variable DB_FOREIGN_KEYS was added to make it easier to handle this in testing (e.g. via phpunit.xml).
jenky pushed a commit to jenky/laravel that referenced this pull request Nov 9, 2018
This enables the sqlite `foreign_key_constraints` option that was introduced with laravel/framework#26298 for all new installs.

The env variable DB_FOREIGN_KEYS was added to make it easier to handle this in testing (e.g. via phpunit.xml).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants