{"record":{"id":"352de2ffd2a7cf77","repo":"phalcon/cphalcon","slug":"the-table-must-contain-at-least-one-column","errorCode":null,"errorMessage":"The table must contain at least one column","messagePattern":"The table must contain at least one column","errorType":"exception","errorClass":"Phalcon\\Db\\Exceptions\\TableMustHaveColumn","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Adapter/AbstractAdapter.zep","lineNumber":324,"sourceCode":"\n        if unlikely !dialect->supportsSavePoints() {\n            throw new SavepointsNotSupported();\n        }\n\n        return this->{\"execute\"}(\n            dialect->createSavepoint(name)\n        );\n    }\n\n    /**\n     * Creates a table\n     */\n    public function createTable( string tableName,  string schemaName,  array definition) -> bool\n    {\n        var columns;\n\n        if unlikely !fetch columns, definition[\"columns\"] {\n            throw new TableMustHaveColumn();\n        }\n\n        if unlikely empty columns {\n            throw new TableMustHaveColumn();\n        }\n\n        return this->{\"execute\"}(\n            this->dialect->createTable(\n                tableName,\n                schemaName,\n                definition\n            )\n        );\n    }\n\n    /**\n     * Creates a view\n     */","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Adapter/AbstractAdapter.zep#L306-L342","documentation":"createTable() requires the $definition array to contain a 'columns' key. The guard '!fetch columns, definition[\"columns\"]' throws TableMustHaveColumn when the key is entirely absent. The columns entry must be a non-empty array of Phalcon\\Db\\Column (ColumnInterface) objects describing each field.","triggerScenarios":"$db->createTable('users', null, ['indexes' => [...]]), ['columns' => ...] omitted; building the definition array dynamically and the columns branch never executes; typo 'column' or 'fileds'/'collumns' as the key name.","commonSituations":"Programmatic schema builders that assemble definition parts conditionally; migrations ported from other tools where the columns block lives elsewhere; copy-paste from createIndex/addColumn examples that omit columns.","solutions":["Add a 'columns' key with Phalcon\\Db\\Column objects: ['columns' => [new Column('id', ['type' => Column::TYPE_INTEGER, 'primary' => true]), ...]]","If the definition is built dynamically, assert isset($definition['columns']) before calling createTable()","Check the key spelling: it must be exactly 'columns'"],"exampleFix":"// before\n$db->createTable('users', null, ['indexes' => $indexes]);\n\n// after\n$db->createTable('users', null, [\n    'columns' => [\n        new Column('id',   ['type' => Column::TYPE_INTEGER, 'primary' => true]),\n        new Column('name', ['type' => Column::TYPE_VARCHAR, 'size' => 100]),\n    ],\n    'indexes' => $indexes,\n]);","handlingStrategy":"validation","validationCode":"if (!isset($definition['columns'])) {\n    throw new InvalidArgumentException('createTable definition needs a \"columns\" key');\n}\n$db->createTable($table, $schema, $definition);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize table-definition building in one factory that always emits a 'columns' entry","Assert the definition shape (columns, optional indexes/references) before calling createTable()","Cover migration builders with unit tests that assert the assembled definition keys"],"tags":["php","phalcon","db","ddl","create-table","schema"],"backgroundTag":"table-missing-column-definition","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}