Skip to content

[Bug]: MySQL datetime with precision fails with CURRENT_TIMESTAMP default #277

Open

Description

@roxblnfk

What happened?

On MySQL a datetime column with a fractional seconds precision and CURRENT_TIMESTAMP as the default can't be created:

$schema = $database->table('events')->getSchema();
$schema->primary('id');
$schema->datetime('created_at', 6)->defaultValue(AbstractColumn::DATETIME_NOW);
$schema->save();
`created_at` datetime (6) NOT NULL DEFAULT CURRENT_TIMESTAMP
SQLSTATE[42000]: 1067 Invalid default value for 'created_at'

MySQL requires the default to have the same precision as the column: DEFAULT CURRENT_TIMESTAMP(6). MySQLColumn renders DATETIME_NOW without it. The same happens with #[Column(type: 'datetime(6)')] on a field managed by CreatedAt / UpdatedAt from cycle/entity-behavior.

Reproduced on MySQL 8.0.37 with cycle/database 2.10.0 and 2.23.3.

Version

cycle/database 2.x, MySQL 8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions