Skip to content

Incorrect syntax for renaming a column with a default method in MySQL #1911

Description

@isaaclyman

Describe the bug
When attempting to rename a column in MySQL 8, if that column has an expression default value (like CURRENT_TIMESTAMP), Fluent Migrator incorrectly includes the cosmetic information DEFAULT_GENERATED in the query, which causes a MySql exception.

To Reproduce

Migration:

Create.Table("my_table").WithColumn("my_column").AsDateTime().NotNullable()
  .WithDefault(SystemMethods.CurrentDateTime);

Rename.Column("my_column").OnTable("my_table").To("anything");

Generated SQL:

ALTER TABLE `my_table` CHANGE `my_column` `anything` datetime NOT NULL DEFAULT `CURRENT_TIMESTAMP` DEFAULT_GENERATED

Error:

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 'DEFAULT_GENERATED' at line 1

Expected behavior
I would expect the rename to ignore the DEFAULT_GENERATED and generate a correct query.

Information (please complete the following information):

  • OS: MacOS Sonoma 14.6.1
  • Platform: .NET Core 8.0
  • FluentMigrator version: 5.2.0
  • FluentMigrator runner: in-process runner
  • Database Management System: MySQL
  • Database Management System Version: 8.0

Additional context
The Phinx migration library for PHP faced a similar issue: cakephp/phinx#2253

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions