Skip to content

Commit 4cf4f0f

Browse files
authored
Merge pull request #6050 from kenjis/fix-sqlite-foreign_keys
fix: add config for SQLite3 Foreign Keys
2 parents c605069 + 214f2d9 commit 4cf4f0f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

system/Database/SQLite3/Connection.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ class Connection extends BaseConnection
3737
*/
3838
public $escapeChar = '`';
3939

40+
/**
41+
* @var bool Enable Foreign Key constraint or not
42+
*/
43+
protected $foreignKeys = false;
44+
45+
public function initialize()
46+
{
47+
parent::initialize();
48+
49+
if ($this->foreignKeys) {
50+
$this->enableForeignKeyChecks();
51+
}
52+
}
53+
4054
/**
4155
* Connect to the database.
4256
*

user_guide_src/source/database/configuration.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ default group's configuration settings. The values should be name following this
105105
Explanation of Values:
106106
**********************
107107

108-
============== ===========================================================================================================
108+
=============== ===========================================================================================================
109109
Name Config Description
110-
============== ===========================================================================================================
110+
=============== ===========================================================================================================
111111
**dsn** The DSN connect string (an all-in-one configuration sequence).
112112
**hostname** The hostname of your database server. Often this is 'localhost'.
113113
**username** The username used to connect to the database.
@@ -140,8 +140,12 @@ Explanation of Values:
140140
**port** The database port number. To use this value you have to add a line to the database config array.
141141

142142
.. literalinclude:: configuration/009.php
143+
**foreignKeys** true/false (boolean) - Whether or not to enable Foreign Key constraint (``SQLite3`` only).
143144

144-
============== ===========================================================================================================
145+
.. important:: SQLite3 Foreign Key constraint is disabled by default.
146+
See `SQLite documentation <https://www.sqlite.org/pragma.html#pragma_foreign_keys>`_.
147+
To enforce Foreign Key constraint, set this config item to true.
148+
=============== ===========================================================================================================
145149

146150
.. note:: Depending on what database platform you are using (MySQL, PostgreSQL,
147151
etc.) not all values will be needed. For example, when using SQLite you

0 commit comments

Comments
 (0)