yiisoft/yii2 · error · yii\base\InvalidConfigException
Transaction::db must be set.
Error message
Transaction::db must be set.
What it means
Error "Transaction::db must be set." thrown in yiisoft/yii2.
Source
Thrown at framework/db/Transaction.php:122
* has no effect. You have to call [[setIsolationLevel()]] in this case after the transaction has started.
*
* > Note: Some DBMS allow setting of the isolation level only for the whole connection so subsequent transactions
* may get the same isolation level even if you did not specify any. When using this feature
* you may need to set the isolation level for all transactions explicitly to avoid conflicting settings.
* At the time of this writing affected DBMS are MSSQL and SQLite.
*
* [isolation level]: https://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels
*
* Starting from version 2.0.16, this method throws exception when beginning nested transaction and underlying DBMS
* does not support savepoints.
* @throws InvalidConfigException if [[db]] is `null`
* @throws NotSupportedException if the DBMS does not support nested transactions
* @throws Exception if DB connection fails
*/
public function begin($isolationLevel = null)
{
if ($this->db === null) {
throw new InvalidConfigException('Transaction::db must be set.');
}
$this->db->open();
if ($this->_level === 0) {
if ($isolationLevel !== null) {
$this->db->getSchema()->setTransactionIsolationLevel($isolationLevel);
}
Yii::debug('Begin transaction' . ($isolationLevel ? ' with isolation level ' . $isolationLevel : ''), __METHOD__);
$this->db->trigger(Connection::EVENT_BEGIN_TRANSACTION);
$this->db->pdo->beginTransaction();
$this->_level = 1;
return;
}
$schema = $this->db->getSchema();
if ($schema->supportsSavepoint()) {View on GitHub (pinned to 66f00d18a2)
When it happens
Trigger: Thrown at framework/db/Transaction.php:122 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/25eb45385a5cd0eb.
Report an issue: GitHub.