2016-09-22 109 views
7

我正在使用MySql作爲官方連接提供程序的數據庫。我的下一個項目例如在MAC嘗試它(asp.net 1.0核心):Dot Net Entity Framework數據庫更新不會在mysql數據庫中創建表

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; } 
} 

在我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(); 
    } 

在我project.json我還加

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

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

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

當我運行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. 
+0

能否請您發表這是執行的代碼表示更新,這是拋出錯誤? – A3006

+0

這是代碼[鏈接](https://github.com/careuno/newtestEfcoreMysql)錯誤是當我執行dotnet ef數據庫更新 –

回答

7

例外說它。 Oracle的官方MySQL提供程序尚不支持它的遷移或腳手架。

它只會在首次執行context.Database.EnsureCreated()時創建數據庫。在此之後所做的任何更改均不適用。您必須刪除整個數據庫並創建一個新數據庫,並丟失所有數據。

說感謝甲骨文)

更新

隨着7.0.6-IR31 package遷移釋放做的工作,但仍腳手架沒有。

+3

謝謝,隨着SapientGuardian.EntityFrameworkCore.MySql工作正常 –

+0

一個鏈接到文檔會有幫助。 –