Error using EF6 Codefirst with Mysql

Asked

Viewed 242 times

0

I have the following error when running Migrations:

inserir a descrição da imagem aqui

How can I fix it? I have everything installed. Follow me Web.Config:

<connectionStrings>
<add name="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>
  • @Gypsy, can you help me ?

  • I’ll check here. Sorry for the delay.

1 answer

1


I found several problems in your configuration. Change your Connection string for:

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

The 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 file Migrations\Configuration.cs. Change the constructor to:

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

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

Try generating a Migration to test the configuration:

PM> Add-Migration Inicial
  • I edited the question to have a better understanding. I have already made the changes you suggested in your answer, but the error still persists. I climbed the project on Github. In case it is useful in the resolution. I thank you already .

  • @Renancarlos Your project has a lot of problems. It’s worth it to start one from scratch and not follow DDD tutorial. Don’t complicate what doesn’t have to be complicated.

  • than explained above, I exchanged a detail in the string Connection. It replaces the Initial Catalog for Database

  • 1

    @Renancarlos Yes. I changed the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.