Pomelo.entityframeworkcore.mysql: Microsoft.EntityFrameworkCore.Database.Command Failed executing DbCommand (rename)

Created on 6 Jul 2020  ·  4Comments  ·  Source: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql

Steps to reproduce

when creating a migration to rename a column you get an exception

The issue

The command to rename the column is not that of mysql

migrationBuilder.RenameColumn(
name: "Name",
table: "User",
newName: "Username");

Microsoft.EntityFrameworkCore.Database.Command[20102] Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] ALTER TABLE `User` RENAME COLUMN `Name` TO `Username`; Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] ALTER TABLE `User` RENAME COLUMN `Name` TO `Username`;

Further technical details

MySQL version: 5.7.30-log MySQL Community Server
Operating system: Windows 10 Pro
Pomelo.EntityFrameworkCore.MySql version: 3.1.1
Microsoft.AspNetCore.App version: 3.1

Other details about my project setup:
All other migrations went smoothly, including AlterColumn and AddColumn

closed-question type-question

Most helpful comment

Your Startup.cs requires ServerVersion(new Version(5, 7, 30), ServerType.MySql) so that Pomelo knows which dialect of MySql to use.

For example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
                options.UseMySql(connectionString,
                    o => o.ServerVersion(new Version(5, 7, 30), ServerType.MySql)
    );

    // ...
}

Does the issue persist after adding this?

All 4 comments

Have you set ServerVersion? In your case ServerVersion(new Version(5, 7, 30), ServerType.MySql)

Check mysql config
image

Your Startup.cs requires ServerVersion(new Version(5, 7, 30), ServerType.MySql) so that Pomelo knows which dialect of MySql to use.

For example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
                options.UseMySql(connectionString,
                    o => o.ServerVersion(new Version(5, 7, 30), ServerType.MySql)
    );

    // ...
}

Does the issue persist after adding this?

great!
it worked, thanks!!!

Was this page helpful?
0 / 5 - 0 ratings