C# 使用efcore从sqlserver更改为mysql
我以前在我的项目中使用MSSQLSERVER,然后我通过安装pomelo mysql客户端并在配置服务中使用它,切换到使用ef core的mysql数据库。当我尝试使用以前从mssql获得的迁移更新新的mysql数据库时,我遇到了一系列错误 最恼人的错误是:C# 使用efcore从sqlserver更改为mysql,c#,mysql,asp.net-core,.net-core,entity-framework-core,C#,Mysql,Asp.net Core,.net Core,Entity Framework Core,我以前在我的项目中使用MSSQLSERVER,然后我通过安装pomelo mysql客户端并在配置服务中使用它,切换到使用ef core的mysql数据库。当我尝试使用以前从mssql获得的迁移更新新的mysql数据库时,我遇到了一系列错误 最恼人的错误是: Microsoft.EntityFrameworkCore.Database.Command[20102] Failed executing DbCommand (4ms) [Parameters=[], CommandTyp
Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE `Activities` (
`Id` uniqueidentifier(36) NOT NULL,
`Title` nvarchar(max) NULL,
`Description` nvarchar(max) NULL,
`Category` nvarchar(max) NULL,
`Date` datetime2(6) NOT NULL,
`City` nvarchar(max) NULL,
`Venue` nvarchar(max) NULL,
CONSTRAINT `PK_Activities` PRIMARY KEY (`Id`)
);
fail: API.Program[0]
An error occured during migration
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corre
sponds to your MySQL server version for the right syntax to use near 'uniqueidentifier(36) NOT NULL,
`Title` nvarchar(max) NULL,
`Descriptio' at line 2
错误指向的迁移文件:
namespace Persistence.Migrations
{
public partial class ActivityEntityAdded : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Activities",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
Title = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
Category = table.Column<string>(nullable: true),
Date = table.Column<DateTime>(nullable: false),
City = table.Column<string>(nullable: true),
Venue = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Activities", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Activities");
}
}
}
namespace Persistence.Migrations
{
公共分部类ActivityEntityAdded:迁移
{
受保护的覆盖作废(MigrationBuilder MigrationBuilder)
{
migrationBuilder.CreateTable(
名称:“活动”,
列:表=>new
{
Id=table.Column(可空:false),
Title=table.Column(可空:true),
Description=table.Column(可空:true),
类别=表.列(可空:true),
日期=表.列(可空:false),
City=表.列(可空:true),
地点=表.列(可空:真)
},
约束:表=>
{
表.PrimaryKey(“PK_活动”,x=>x.Id);
});
}
受保护的覆盖无效关闭(MigrationBuilder MigrationBuilder)
{
migrationBuilder.DropTable(
名称:“活动”);
}
}
}
有人能告诉我如何修复这个错误吗?或者mysql目前还不支持GUI?
请任何输入将不胜感激 @IanKemp问题代码由EF核心工具自动生成。为一个提供程序生成的迁移不能与另一个提供程序一起使用。请参阅EF核心文档的一节。@IvanStoev由EF核心工具为MSSQL生成。然后询问者尝试在MySQL上运行相同的迁移,猜猜有什么不起作用。他们没有研究原因,而是向堆栈溢出抛出了一个问题,希望我们能为他们解决所有问题。哇,好的。因此,我必须使用mysql?@IanKemp从头开始重新创建所有代码,但您应该承认,EF核心方法并不那么直观,特别是对于来自EF6的人来说,在EF6中生成的迁移与数据库无关,文档很容易丢失。