2

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 http://go.microsoft.com/fwlink/?LinkId=260882 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

2
  • 1
    Obviously not all of the providers point to SQLServer Commented Sep 21, 2016 at 0:44
  • Very obvious indeed, so much that I tried to check where could that be and couldn't find. Even when I do a full text search on all solution files I cannot find a trace of the word: "Mysql" Here is my only config file: pastebin.com/FVf31aJ9 If you find where the wrong provider is set please let me know :) Commented Sep 21, 2016 at 7:41

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I am gonna try this and come back to you. I didn't try yet to rebuild the migrations.
I did this and it works fine. Thanks a ton for that! That being said, I am annoyed by the fact I loose the history of migrations, because of course when I regenerate the migrations it only creates a single one with the current state of the database, while on the mysql side I had 3 different migrations classes. I tried to compare both the new single migration and the other three mysql migration classes and the only change that is probably causing the issue is the has stored in the resx file in the target field. I guess there is the reference to the MySql provider. Is there a way ...
... to regenerate just the target field while keeping the old migration classes?
Glad to see that above solution works :) Hope you'll accept the solution with Up vote :D to regenerate just the target field while keeping the old migration classes - Actually that way it won't work.you can try that on separate project.I'm pretty much sure where it won't work.
I had to wonder around on how to mark it as the right answer but I figured it out (should ask questions more often :D) I am trying several things but indeed it seems to be impossible to recover those migrations, it is a pity. In this project it doesn't matter much since it is not in production yet but this could become annoying otherwise
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.