SQLite Foreign Key Enable: Manual Enabling required (since Part-DB 2.15) #1486
Pinned
jbtronics
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
SQLite foreign key check
Unlike MySQL and PostgreSQL, Sqlite does not check foreign key relationships by default, and this did not happened so far when Part-DB was used with Sqlite as platform.
It helps against data corruption and is highly recommend though, therefore there is now a new
DATABASE_SQLITE_ENFORCE_FOREIGN_KEYSenv variable to enable foreign key checks for Sqlite.For backwards compatibility reasons its disabled by default however. For new database instances it is riskless, but for existing databases which already contains invalid data that breaks the foreign keys it could cause issues. There is a console command to help migration however.
How to do the migration
php bin/console partdb:database:check-sqlite-foreign-keys(orsudo docker exec --user=www-data partdb php bin/console partdb:database:check-sqlite-foreign-keysto see if your database contains any violations.DATABASE_SQLITE_ENFORCE_FOREIGN_KEYSenv to 1. Otherwise:php bin/console partdb:database:check-sqlite-foreign-keys --fix, it will update/delete invalid entries, so that they should not cause problemsDATABASE_SQLITE_ENFORCE_FOREIGN_KEYS=1in your.env.local(in direct installation) or your docker-compose.yaml (for docker environments)In the future the default value will change to 1 for everyone, it makes sense to do the migration as soon as possible.
All reactions