Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为EF 6.4和MySQL C启用迁移?_C#_Mysql_Entity Framework 6_Migration_Entity Framework Migrations - Fatal编程技术网

C# 如何为EF 6.4和MySQL C启用迁移?

C# 如何为EF 6.4和MySQL C启用迁移?,c#,mysql,entity-framework-6,migration,entity-framework-migrations,C#,Mysql,Entity Framework 6,Migration,Entity Framework Migrations,我尝试使用命令启用迁移 启用迁移 但我得到了下面的错误,我真的不知道如何解决它 我安装了所有的扩展以使其正常工作。 错误消息: Checking if the context targets an existing database... No MigrationSqlGenerator found for provider 'MySql.Data.MySqlClient'. Use the SetSqlGenerator method in the target migrations con

我尝试使用命令启用迁移

启用迁移

但我得到了下面的错误,我真的不知道如何解决它

我安装了所有的扩展以使其正常工作。

错误消息:

Checking if the context targets an existing database...
No MigrationSqlGenerator found for provider 'MySql.Data.MySqlClient'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.

我假设您的项目是一个.net核心应用程序,并且您使用的是visual studio

  • 确保已从Nuget软件包管理器安装Microsoft.Entityframeworkcore.tools
  • 从PackageManager控制台,您不需要像前面在EF5中那样启用迁移
  • 只需运行添加迁移{MigrationName}
  • 运行更新数据库以更新数据库
  • 如果AppDbContext与启动文件位于同一项目中
  • 运行dotnet ef迁移添加{MigrationName}
  • 运行dotnet ef-database update以更新数据库
  • 如果AppDbContext位于不同的项目中,请从命令行打开包含该项目的根目录
  • 运行dotnet ef迁移添加{MigrationName}--s../{startupproject}/{startupproject.csproj}
  • 运行dotnet ef-database update来更新数据库--s../{startupproject}/{startupproject.csproj}

  • 正如错误消息所说,您需要首先更改MigrationSqlGenerator。

    您可以通过两种方式完成:

    修改App.Config中的entityFramework部分

    <entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly">
        ...Your EF config...
    </entityFramework>
    
    对于MySql.Data.Entity->MySql.Data(>=6.10.9)

    对于MySql.Data.EntityFramework->MySql.Data(>=8.0.20)

    [DbConfigurationType("MyNamespace.MyDbConfiguration, MyAssembly")]
    public class MyContextContext : DbContext
    {
    }
    
    <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
        <providers>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
        ...other providers
        </providers>
      </entityFramework>
    
    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6))]
    public class DemoContext : DbContext
    {
    }
    
    <entityFramework codeConfigurationType="MySql.Data.EntityFramework.MySqlEFConfiguration, MySql.Data.EntityFramework">
        <providers>
          <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.20.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
        ...other providers
        </providers>
      </entityFramework>
    
    [DbConfigurationType(typeof(MySql.Data.EntityFramework.MySqlEFConfiguration, MySql.Data.EntityFramework))]
    public class DemoContext : DbContext
    {
    }