-
I am using SQLite3 db with CI4 and Shield. When I purge user from db, only the entry in the users table is deleted, while the other table entries related to the same user remain. This is because SQLite3 by default does not enforece foreign keys, so the change in users table does not cascade to the other related tables. However, I cannot seem to find a way to force that behaviour. The DB is created using the migration procedure, and it does include foreign keys like CREATE TABLE IF NOT EXISTS "auth_identities" ( I have entered a piece of code
Into the BaseController.php initController function, which should enforce the foreign keys, but it does not do the trick. Maybe anyone happens to understand why it might be so? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
OK, so I have realized that the app BaseController.php was not run in my app case (it is the default Bonfire2 install). When I put it in another place and added another simple query after it that deletes one of the users, it got executed and the user was deleted with all dependent entries. That far – good. I am still not sure where to put that code so that it covers my whole Bonfire2 app, but that is perhaps not the problem with Shield. However, I would suggest that, since Codeigniter 4 officially supports SQLite3, the Shield should perhaps enforce foreign keys by default in case the database is SQLite3. Another way would be to refactor code so that the code is not dependent on the database enforcing foreign key constraints. |
Beta Was this translation helpful? Give feedback.
-
There is a config variable for this. Please see https://www.codeigniter.com/user_guide/database/configuration.html#explanation-of-values - the last option in the table: |
Beta Was this translation helpful? Give feedback.
There is a config variable for this. Please see https://www.codeigniter.com/user_guide/database/configuration.html#explanation-of-values - the last option in the table:
foreignKeys
.