Bug #118288 Error with the alter name command MySql.EntityFrameworkCore
Submitted: 28 May 13:03 Modified: 5 Jun 6:38
Reporter: Matheus Resende Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:9.0.3 OS:Any
Assigned to: CPU Architecture:Any

[28 May 13:03] Matheus Resende
Description:
I'm using an ORM (Entity Framework Core with MySQL) that auto-generates SQL commands from migrations.

I've encountered a critical issue when the database schema name contains a dot (.) — for example: travel.route.

In MySQL, the dot is a reserved character used to separate schema and table names. As a result:

All RENAME operations fail during migration generation.

This issue happens specifically in the second name of the command — the new name of the table or index.

The first name (the current table name) is recognized correctly by MySQL.

But the second name (new name), since it contains a dot and is not escaped with backticks (`), causes a syntax error due to the dot being interpreted as a reserved token.

Note: Other commands like CREATE, DROP, ALTER work normally, even with a dot in the schema name. The issue happens only with RENAME statements.

Failed executing DbCommand (209ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE travel.route.PointDetail RENAME travels.RoutePointDetail;

MySql.Data.MySqlClient.MySqlException (0x80004005):
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 '.PointDetail RENAME travels.RoutePointDetail' at line 1

To work around this issue, I had to manually edit the generated migration and wrap the new table name in backticks:

migrationBuilder.RenameIndex(
    name: "IX_trv.Companion_RoutePointId",
    table: "trv.Companion",
    newName: "`IX_trv.Companion_TravelId`");

How to repeat:
In your entity mapping or migration code, define a table or schema name that contains a dot.

Example:
builder.ToTable("Companion"); To builder.ToTable("trv.Companion");
Make a structural change in the entity that causes EF Core to generate a RENAME operation during migration, such as renaming the table or a related index.

Generate a new migration:
dotnet ef migrations add RenameTest

EF Core will generate something like:

migrationBuilder.RenameTable(
    name: "Companion",
    newName: "trv.Companion");

Apply the migration

You will get a syntax error when the migration executes:
MySql.Data.MySqlClient.MySqlException (0x80004005):
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 '.Companion RENAME TO trv.section.Companions' at line 1

Suggested fix:
To prevent syntax errors in MySQL caused by special characters such as dots (.) in table or schema names, the migration generator should always wrap the newName value in backticks when generating RenameTable, RenameIndex, and similar operations.

For example, instead of generating:
migrationBuilder.RenameTable(
    name: "Companion",
    newName: "trv.Companion");

It should generate:
migrationBuilder.RenameTable(
    name: "Companion",
    newName: "`trv.Companion`");
Applying backticks to all newName values ensures that MySQL interprets them as literal identifiers, preventing parsing issues and syntax errors in cases where names include dots or other reserved characters.
[5 Jun 6:38] MySQL Verification Team
Hello Matheus,

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil