PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How to enable migration for EF 6.4 and MySQL C#?

 April 13, 2022     c#, entity-framework-6, entity-framework-migrations, migration, mysql     No comments   

Issue

I tried to enable migrations using the command

Enable-Migrations

But I got the error below, I didn't really understand how to solve it...

I installed all the extensions to make it works. enter image description here

The error message :

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.

Solution

as the error message says, you need to change first the MigrationSqlGenerator. https://docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/code-based

you can do it in 2 ways:

modify the entityFramework section in your App.Config

<entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly">
    ...Your EF config...
</entityFramework>

OR add the DbConfigurationType attribute to your DbContext inherited class

[DbConfigurationType("MyNamespace.MyDbConfiguration, MyAssembly")]
public class MyContextContext : DbContext
{
}

for MySql.Data.Entity -> MySql.Data (>= 6.10.9)

<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
{
}

for MySql.Data.EntityFramework -> MySql.Data (>= 8.0.20)

<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
{
}


Answered By - jrivam
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,259,905

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing