简体   繁体   English

Dot Net Entity Framework数据库更新不会在mysql数据库中创建表

[英]Dot Net Entity Framework database update doesn't create tables in mysql database

I'm using MySql as database with the official connection provider. 我正在使用MySql作为官方连接提供程序的数据库。 I'm trying it with the next project example (asp.net core 1.0) on a mac: 我正在尝试使用mac上的下一个项目示例(asp.net core 1.0):

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 在我的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 在我的project.json中我也添加了

"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 当我运行dotnet ef migrations add v1 ,工作正常并创建迁移文件,但是当我执行dotnet ef database update ,数据库被创建但是表没有并抛出此输出

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.

Exceptions says it. 例外说它。 The official MySQL Provider from Oracle doesn't support it migrations or scaffolding yet. Oracle的官方MySQL提供程序尚不支持迁移或脚手架。

It will only create the Database on first execution of context.Database.EnsureCreated() . 它只会在首次执行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. 随着7.0.6-IR31 软件包的发布,迁移确实有效,但脚手架仍然没有。

As Tseng said, this is a known issue. 正如Tseng所说,这是一个众所周知的问题。 Here is the bug report from 14 Sept 2016. 这是2016年9月14日的错误报告。

Missing implementation for running EntityFramework Core code first migration 缺少运行EntityFramework核心代码的实现首次迁移

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM