Bug #66355 unable to add ef migration
Submitted: 13 Aug 2012 15:56 Modified: 7 Sep 2012 22:02
Reporter: luca morelli Email Updates:
Status: Not a Bug Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:6.6.1 OS:Microsoft Windows (windows 7 64 bit)
Assigned to: Gabriela Martinez Sanchez CPU Architecture:Any
Tags: .net entity framework

[13 Aug 2012 15:56] luca morelli
unable to use mysql to create a ef code first migration database and add migration

How to repeat:
created a new winform project, framework 4.0, added entityframework 4.3.1, added mysql.data and mysql.data.entity from installation directory.
created dbcontext, added a table, created 2 connection strings, one for sql server and 1 for mysql.
enabled mygrations and add-migration in sql server ok, running the command

Update-Database -TargetMigration "inizio" -ConnectionStringName "MySqlTextContext" -Verbose

i receive the error message

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at System.Data.Entity.Migrations.DbMigrationsConfiguration.GetSqlGenerator(String providerInvariantName)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The given key was not present in the dictionary.
[14 Aug 2012 17:20] Gabriela Martinez Sanchez
Hi Luca, thanks for your bug report. In order to use the Migrations first you should create the Configuration class so EF can recognize our provider. The syntax to use for that is like this:

//Include C/Net Namespace of Entity Framework

  using MySql.Data.Entity;

    internal sealed class Configuration : DbMigrationsConfiguration</*NameOfYourContext*/>
        public Configuration()
            AutomaticMigrationsEnabled = false;
            SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());  

        protected override void Seed(/*NameOfYourContext*/ context)

After adding this class you should be able to add Migrations to your database. 

Please let us know if after doing this you still have any problems.
[15 Aug 2012 8:30] luca morelli
thank you very much: tried and it works.
i would like to know if is possible to set the sqlgenerator via app.config or web.config file
[15 Aug 2012 15:03] Gabriela Martinez Sanchez
Hi Luca, glad it worked. And no, the only way so far is creating the Configuration  class. We'll be doing some tutorials later this week in case you want to check them later in our blog (blogs.oracle.com/MySqlOnWindows/) and you can post your questions in the forums too (forums.mysql.com/list.php?38).
[7 Sep 2012 22:02] Gabriela Martinez Sanchez
Closing the bug since there is no other feedback or question from the user and it has been also responded as not a bug but a code error.