{"record":{"id":"f10b741e1801f05a","repo":"phalcon/cphalcon","slug":"dropping-a-check-constraint-is-not-supported-by-sq","errorCode":null,"errorMessage":"Dropping a CHECK constraint is not supported by SQLite","messagePattern":"Dropping a CHECK constraint is not supported by SQLite","errorType":"exception","errorClass":"Phalcon\\Db\\Exceptions\\SqliteDropCheckNotSupported","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Dialect/Sqlite.zep","lineNumber":366,"sourceCode":"     * Generates SQL to delete a column from a table.\n     *\n     * SQLite 3.35+ supports `ALTER TABLE ... DROP COLUMN ...` directly. On\n     * older versions the server rejects the statement at execution time;\n     * cphalcon no longer pre-empts that rejection at the dialect level so\n     * callers on 3.35+ can use the feature.\n     */\n    public function dropColumn( string tableName,  string schemaName,  string columnName) -> string\n    {\n        return \"ALTER TABLE \" . this->prepareTable(tableName, schemaName)\n            . \" DROP COLUMN \\\"\" . columnName . \"\\\"\";\n    }\n\n    /**\n     * SQLite cannot DROP a CHECK constraint from an existing table.\n     */\n    public function dropCheck( string tableName,  string schemaName,  string checkName) -> string\n    {\n        throw new SqliteDropCheckNotSupported();\n    }\n\n    /**\n     * Generates SQL to delete a foreign key from a table\n     */\n    public function dropForeignKey( string tableName,  string schemaName,  string referenceName) -> string\n    {\n        throw new SqliteDropForeignKeyNotSupported();\n    }\n\n    /**\n     * Generates SQL to delete an index from a table\n     */\n    public function dropIndex( string tableName,  string schemaName,  string indexName) -> string\n    {\n        if schemaName {\n            return \"DROP INDEX \\\"\" . schemaName . \"\\\".\\\"\" . indexName . \"\\\"\";\n        }","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Dialect/Sqlite.zep#L348-L384","documentation":"Phalcon\\Db\\Dialect\\Sqlite::dropCheck() always throws SqliteDropCheckNotSupported. SQLite has no ALTER TABLE ... DROP CONSTRAINT statement — a CHECK constraint can only be removed by recreating the table — so the dialect refuses to generate SQL instead of emitting a statement the engine would reject.","triggerScenarios":"Running shared migration code that calls $connection->dropCheck('posts', 'chk_title') while the connection's dialect is Sqlite; re-applying constraint changes uniformly across MySQL/PostgreSQL and SQLite environments.","commonSituations":"CI suites running migrations against an in-memory SQLite database; multi-database applications reusing MySQL migrations; scaffolding tools that introspect and re-apply constraints identically on every dialect.","solutions":["Gate the call on the dialect: skip dropCheck() when $connection->getDialectType() === 'sqlite'","Emulate with the SQLite table-rebuild procedure: create a new table without the CHECK, copy the rows, drop the old table, rename the new one","Move the constraint drop into a migration tagged for databases that support it (MySQL/PostgreSQL)"],"exampleFix":"// before\n$connection->dropCheck('posts', 'chk_title');\n\n// after\nif ($connection->getDialectType() !== 'sqlite') {\n    $connection->dropCheck('posts', 'chk_title');\n}\n// on SQLite, rebuild the table instead of dropping the CHECK","handlingStrategy":"try-catch","validationCode":"if ($connection->getDialectType() !== 'sqlite') {\n    $connection->dropCheck('posts', 'chk_title');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $connection->dropCheck('posts', 'chk_title');\n} catch (\\Phalcon\\Db\\Exceptions\\SqliteDropCheckNotSupported $e) {\n    // SQLite cannot drop CHECK constraints; rebuild the table or skip\n    $logger->info('Skipped dropCheck on SQLite', ['table' => 'posts']);\n}","preventionTips":["Make migrations dialect-aware: branch on $connection->getDialectType()","Run the full migration set against SQLite in CI so unsupported operations surface before production","For SQLite-managed schemas, define CHECK constraints only in the initial CREATE TABLE"],"tags":["sqlite","phalcon-db","ddl","check-constraint","unsupported-operation","migrations"],"backgroundTag":"sqlite-alter-limitation","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}