Carlos Carlos - 1 month ago 6x
MySQL Question

EF Code First Mysql to SQL Server

I have an MVC 5 application that I first configured to use Mysql but now would like it to use SQL Server.

My app uses code first and migrations in order to generate the database.

After I changed all the required configuration I tried to run a Update-Database from the Package management console but I keep getting this error:

System.Data.Entity.Core.MetadataException: Schema specified is not
valid. Errors: (0,0) : error 0152: 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 for more information.

This error appears after the database is created. It also appears when I run the application since it checks at that moment if there is any migration to do.

Somehow it still tries to use MySQL even though all providers point to SQL Server.

Any help would be more than welcome.

Thanks in advance


You need to follow the below mentioned steps to overcome above issue.

Step 1 : Use NuGet package to remove and install the relevant packages.This is very important.

If it's not working after the above step then you have to follow the below mentioned steps.

Step 1 : Get a backup of your project and SQL db and keep it in a safe place.

Step 2 : After that you have to delete all your data migration scripts on your app.

Step 3 : Delete the SQL db also.

Step 4 : Recreate all your Migration scripts again and after that run those against the SQL server.

Note : You need to do above steps b'cos it seems EF keep the provider details on the db migration scripts.