9

I'm using MySql as database with the official connection provider. I'm trying it with the next project example (asp.net core 1.0) on a mac:

public class BloggingContext : DbContext
{
    public BloggingContext(DbContextOptions<BloggingContext> options)
        : base(options)
    { }

    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }
}

public class Blog
{
    public int BlogId { get; set; }
    public string Url { get; set; }

    public List<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }

    public int BlogId { get; set; }
    public Blog Blog { get; set; }
}

And in my Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        var connection = @"server=localhost;userid=efcore;port=3306;database=blogsFinal;sslmode=none;";
        services.AddDbContext<BloggingContext>(options => options.UseMySQL(connection));

        // Add framework services.
        services.AddMvc();
    }

In my project.json I also add

"dependencies": {
   ...
     "MySql.Data.EntityFrameworkCore": "7.0.5-ir21",

    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
}

and

  "tools": {
    ...,
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

When I run dotnet ef migrations add v1, works fine and creates the migration files, but when I execute dotnet ef database update the database is created but tables not and throws this output

System.NotImplementedException: The method or operation is not implemented.
   at MySQL.Data.EntityFrameworkCore.Migrations.Internal.MySQLHistoryRepository.get_ExistsSql()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
The method or operation is not implemented.
2
  • Could you please post the code which is executing for said Update, which is throwing error?
    – A3006
    Sep 22, 2016 at 13:19
  • This is the code link the error is when I execute dotnet ef database update Sep 22, 2016 at 13:48

2 Answers 2

8

Exceptions says it. The official MySQL Provider from Oracle doesn't support it migrations or scaffolding yet.

It will only create the Database on first execution of context.Database.EnsureCreated(). Any changes done after that, won't be applied. You have to drop the whole DB and create a new one, losing all data.

Say thanks to Oracle ;)

Update

With the release of 7.0.6-IR31 package migrations do work, but scaffolding still doesn't.

2
  • 3
    Thank you, With SapientGuardian.EntityFrameworkCore.MySql works fine Sep 22, 2016 at 14:28
  • A link to the documentation would be helpful. Sep 22, 2016 at 15:05
1

As Tseng said, this is a known issue. Here is the bug report from 14 Sept 2016.

Missing implementation for running EntityFramework Core code first migration

http://bugs.mysql.com/bug.php?id=82981

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.