Bug #91030 Entity Framework Code-First Migration to database does not work
Submitted: 25 May 2018 17:05 Modified: 31 May 2018 11:54
Reporter: Bari Tobi Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.11 OS:Microsoft Windows
Assigned to: CPU Architecture:x86
Tags: entity framework

[25 May 2018 17:05] Bari Tobi
Using Entity Framework with latest versions of libraries (See "how to repeat" section), it no longer works to do a code-first migration. I.e. set up the domain model in code and then let the Entity Framework via the MySql Entity Framework connector create the equivalent database tables. This used to work in a previous version.

The error message I get is that there is something wrong with the database connection string although it is a very simple one and working in the previous version. I doubt that this is the problem. I would suggest that the error message handling was improved too to give some more information on what is really wrong. There seem to be many people on various forums that are puzzled by this error message and there seem to be many reasons for it to appear not all related to the connection string.

The error occurs when issuing the "enable-migrations" command in the Packet manage Console according to the article. The error message you get is:

"An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure."

Inner Exception stack is:
System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.MethodAccessException: Attempt by method 'MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)' to access method 'MySql.Data.MySqlClient.MySqlConnection.get_Settings()' failed.
   at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)

How to repeat:
My VS library versions:
- Entity Framework 6.2.0 (though it states in 6.0.0, I know 6.2 is installed via NuGet)
- MySql.Data v8.0.11
- MySql.data.Entity 6.10.7

There is a blog description of how to work around this in an older version of .net (4.5) using older versions of the needed libraries: https://vnextcoder.wordpress.com/2015/10/04/mysql-net-entity-framework-code-first-migratio...

Downloading the test code in that article (link to GitHub repository link at the end of article), it is possible to make it work with those libraries he used following the blog post. (however, there is an app.config updated needed that he does not explicitly state: Change MySql.Data.Entity.EF6 v6.9.7.0 to v6.8.3.0 according to the version that actually works).

Since the code has not changed, not the connection string, I assume this is a bug or a breaking change in some library upgrade.

Suggested fix:
Use the code in that blog. Update binaries to the latest version and make it work.
[25 May 2018 17:14] Bari Tobi
Updated bug report. Version number was wrong by mistake.
[31 May 2018 11:54] Chiranjeevi Battula
Hello Tob Fja,

Thank you for the bug report.
Verified based on internal discussion with dev's.

[25 Jun 2018 11:18] Paul Reeder
I had the same problem.  In order to work around it, I had to downgrade to:

MySql.Data - 6.9.12 (6.10.7 and 8.0.11 exhibited the problem)
MySQL.Data.Entity - 6.8.8 (6.9.12 and 6.10.7 exhibited the problem)

I did not have to downgrade EntityFramework from 6.2.0
[6 Nov 2018 12:19] Gianpiero Caretti
I had the same problem.  But I solved the issue by upgrading to:

MySql.Data - 8.0.13
MySQL.Data.Entity - 6.10.8

I did not have to downgrade EntityFramework from 6.2.0
[31 Jan 22:17] Bernhard Doebler
I get this message "{"The provider did not return a ProviderManifestToken string."}" While I'm on latest versions :(

  <package id="MySql.Data" version="8.0.14" targetFramework="net46" />
  <package id="MySql.Data.Entity" version="6.10.8" targetFramework="net46" />
[6 Apr 11:11] robert ivanc
It's been 10 months on this critical bug, and no fix?? Seriously? 
How this even get through your testing?