{"record":{"id":"25eb45385a5cd0eb","repo":"yiisoft/yii2","slug":"transaction-db-must-be-set","errorCode":null,"errorMessage":"Transaction::db must be set.","messagePattern":"Transaction::db must be set\\.","errorType":"exception","errorClass":"yii\\base\\InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/db/Transaction.php","lineNumber":122,"sourceCode":"     * has no effect. You have to call [[setIsolationLevel()]] in this case after the transaction has started.\n     *\n     * > Note: Some DBMS allow setting of the isolation level only for the whole connection so subsequent transactions\n     * may get the same isolation level even if you did not specify any. When using this feature\n     * you may need to set the isolation level for all transactions explicitly to avoid conflicting settings.\n     * At the time of this writing affected DBMS are MSSQL and SQLite.\n     *\n     * [isolation level]: https://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels\n     *\n     * Starting from version 2.0.16, this method throws exception when beginning nested transaction and underlying DBMS\n     * does not support savepoints.\n     * @throws InvalidConfigException if [[db]] is `null`\n     * @throws NotSupportedException if the DBMS does not support nested transactions\n     * @throws Exception if DB connection fails\n     */\n    public function begin($isolationLevel = null)\n    {\n        if ($this->db === null) {\n            throw new InvalidConfigException('Transaction::db must be set.');\n        }\n        $this->db->open();\n\n        if ($this->_level === 0) {\n            if ($isolationLevel !== null) {\n                $this->db->getSchema()->setTransactionIsolationLevel($isolationLevel);\n            }\n            Yii::debug('Begin transaction' . ($isolationLevel ? ' with isolation level ' . $isolationLevel : ''), __METHOD__);\n\n            $this->db->trigger(Connection::EVENT_BEGIN_TRANSACTION);\n            $this->db->pdo->beginTransaction();\n            $this->_level = 1;\n\n            return;\n        }\n\n        $schema = $this->db->getSchema();\n        if ($schema->supportsSavepoint()) {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/Transaction.php#L104-L140","documentation":"Error \"Transaction::db must be set.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/Transaction.php:122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}