{"record":{"id":"e2749d27c5e5eb50","repo":"yiisoft/yii2","slug":"primary-key-key-cannot-be-found-in-table-thi","errorCode":null,"errorMessage":"Primary key '$key' cannot be found in table '{$this->name}'.","messagePattern":"Primary key '\\$key' cannot be found in table '(.+?)'\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/TableSchema.php","lineNumber":100,"sourceCode":"    }\n\n    /**\n     * Manually specifies the primary key for this table.\n     * @param string|array $keys the primary key (can be composite)\n     * @throws InvalidArgumentException if the specified key cannot be found in the table.\n     */\n    public function fixPrimaryKey($keys)\n    {\n        $keys = (array) $keys;\n        $this->primaryKey = $keys;\n        foreach ($this->columns as $column) {\n            $column->isPrimaryKey = false;\n        }\n        foreach ($keys as $key) {\n            if (isset($this->columns[$key])) {\n                $this->columns[$key]->isPrimaryKey = true;\n            } else {\n                throw new InvalidArgumentException(\"Primary key '$key' cannot be found in table '{$this->name}'.\");\n            }\n        }\n    }\n}\n","sourceCodeStart":82,"sourceCodeEnd":105,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/TableSchema.php#L82-L105","documentation":"Error \"Primary key '$key' cannot be found in table '{$this->name}'.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/TableSchema.php:100 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"}