除了一个问题,我已经将SQL2012数据库迁移到MySQL。

当我连接到MySQL数据库时,出现以下错误。

初始化数据库时发生异常。

InnerException有关详细信息:
指定的架构无效。
错误:(0,0):错误0040:类型nvarchar(max)不具有名称空间或别名。
没有限制,只能使用原始类型。

对于我类中的每个String属性,都会发生这种情况。

我尝试了以下方法:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        { modelBuilder.HasDefaultSchema(String.Empty);}


但是我仍然得到错误。

是否有人提出可以解决问题的建议。

我也曾尝试生成MySQL迁移,但出现以下错误:

No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.


有没有一种在代码中设置MySQLProvider的方法?

这是我的DBConfiguration:

    public class EF6MySQLDbConfiguration : DbConfiguration
  {
    public EF6MySQLDbConfiguration()
    {
      if (CustomConnectionFactory.ServerName == "MySQL")
      {
        SetExecutionStrategy(MySql.Data.Entity.MySqlProviderInvariantName.ProviderName, () => new MySql.Data.Entity.MySqlExecutionStrategy());
        AddDependencyResolver(new MySql.Data.Entity.MySqlDependencyResolver());
        //Type t = typeof(MySqlProviderServices);
      }
      SetDefaultConnectionFactory(new CustomConnectionFactory());
    }


为了克服迁移历史记录表时的问题,我添加了:

public Configuration()
    {
        AutomaticMigrationsEnabled = false;

        if (EF6MySQL.DataAccess.CustomConnectionFactory.ServerName == "MySQL")
        {
          SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
          SetHistoryContextFactory("MySql.Data.MySqlClient", (conn, schema) => new MySql.Data.Entity.MySqlHistoryContext(conn, schema));
        }
    }

最佳答案

解决方案是添加以下行:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
  if (CustomConnectionFactory.ServerName == "MySQL")
  {
    modelBuilder.Properties<String>().Configure(c => c.HasColumnType("longtext"));
  }}


The second answer provided here contained invaluable information to setup the 2 different databases.

关于mysql - 迁移到指定的MySQL和架构无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27495352/

10-11 03:22
查看更多