Skip to content

Numeric column comment produces SQL syntax error with MySQL #889

@nook24

Description

@nook24

Since I upgrade from CakePHP 4 to 5, numeric column comments are producing a SQL syntax error (MySQL):

<?php
declare(strict_types=1);

class Initial extends \Migrations\BaseMigration {

    public bool $autoId = false;

    public function change(): void {
        if (!$this->hasTable('jira_issues')) {
            $this->table('jira_issues')
                // ...
                ->addColumn('issue_key', 'string', [
                    'default' => null,
                    'limit'   => 255,
                    'null'    => false,
                    'comment' => 'ITC-123'  // <-- This is ok
                ])
                ->addColumn('issue_id', 'string', [
                    'default' => null,
                    'limit'   => 255,
                    'null'    => false,
                    'comment' => '10102' // <-- SQL Syntax error
                ])
                ->create();
        }
    }
}

The generated SQL query is missing quotes:

CREATE TABLE `jira_issues` (
    `id`              INTEGER NOT NULL auto_increment,
    `jira_project_id` INTEGER NOT NULL,
    `host_id`         INTEGER NOT NULL,
    `service_id`      INTEGER,
    `issue_key`       VARCHAR(255) NOT NULL comment 'ITC-123',
    `issue_id`        VARCHAR(255) NOT NULL comment 10102,
    `state`           INTEGER NOT NULL DEFAULT 0,
    `created`         datetime NOT NULL,
    `modified`        datetime NOT NULL,
    PRIMARY KEY (`id`),
    KEY (`issue_key`),
    KEY (`host_id`,`service_id`)
) engine = innodb CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

Error while running the migration

 == 20250115132442 Initial: migrating
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10102, `state` INTEGER NOT NULL DEFAULT 0, `created` DATETIME NOT NULL, `modifie' at line 1
Query: CREATE TABLE `jira_issues` (`id` INTEGER NOT NULL AUTO_INCREMENT, `jira_project_id` INTEGER NOT NULL, `host_id` INTEGER NOT NULL, `service_id` INTEGER, `issue_key` VARCHAR(255) NOT NULL COMMENT 'ITC-123', `issue_id` VARCHAR(255) NOT NULL COMMENT 10102, `state` INTEGER NOT NULL DEFAULT 0, `created` DATETIME NOT NULL, `modified` DATETIME NOT NULL, PRIMARY KEY (`id`),  KEY (`issue_key`),  KEY (`host_id`,`service_id`)) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
Importing default records for JiraModule into database

CakePHP Version: 5.2.6
Migration Version: 4.7.0 (@stable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions