簡體   English   中英

在AWS上部署時,MySQL表不存在

[英]MySQL Table doesn't exist when deployed on AWS

我將.net核心應用程序部署到aws,但無法弄清楚如何進行初始遷移以創建表。 是否有一些等同於dotnet ef migrations add Initial dotnet ef database update在使用Code First方法時在aws上dotnet ef migrations add Initial dotnet ef database update以創建表? 我的代碼在線失敗:

if (context.Record.Any())
            {
                return;   // DB has been seeded
            }

通過將MySQL連接器從MySql.Data.EntityFrameworkCore更改為SapientGuardian.EntityFrameworkCore.MySql來解決問題。 然后使用默認命令執行所有遷移。

與開發相同。

您必須在應用程序啟動期間調用dbContext.Database.EnsureCreated()Configure方法)。

您需要創建一個服務范圍,然后解決您的DbContext

public void Configure(IApplicationBuilder app)
{
    using (var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
    {
        using (var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>())
        {
            if (dbContext.Database.EnsureCreated())
            {
                // Seed your database if necessary
            }
        }
    }
}

現在,這是創建表的唯一方法,因為Oracle尚未實現遷移或腳手架。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM