Error when using EF6 CodeFirst with Mysql

0

I have the following error when I run Migrations:

HowcanIsolveit?Ihaveeverythingproperlyinstalled.Here'smyWeb.Config:

<connectionStrings><addname="ProjetoCultContext" providerName="MySql.Data.MySqlClient"   connectionString="server=localhost;port=3306;Initial  Catalog=ProjetoCultContex;uid=root;pwd=******;" />
</connectionStrings>

And the Entity Framework configuration:

<entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory,   MySql.Data.Entity.EF6" />
    <providers>
    <provider invariantName="MySql.Data.MySqlClient"    type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
</entityFramework>
    
asked by anonymous 11.04.2016 / 22:36

1 answer

1

I found several problems in your configuration. Change your connection string to:

<connectionStrings>
  <add name="NortaoCultContext" providerName="MySql.Data.MySqlClient" connectionString="server=127.0.0.1;port=3306;Database=NortaoCultContex;uid=root;pwd=********;" />
</connectionStrings>

Entity Framework configuration:

  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider>
    </providers>
  </entityFramework>

Open the Package Manager Console and type:

PM> Enable-Migrations

Visual Studio will generate the Migrations\Configuration.cs file. Change the constructor to:

    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        AutomaticMigrationDataLossAllowed = true;

        SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
    }

Try to generate a Migration to test the configuration:

PM> Add-Migration Inicial
    
29.06.2016 / 00:25