我将我的.net核心应用程序部署到aws中,但不知道如何进行初始迁移以创建表。在使用代码第一方法时,是否存在与aws上的dotnet ef migrations add Initial dotnet ef database update等效的创建表的方法?我的代码在网上失败:
if (context.Record.Any())
{
return; // DB has been seeded
}发布于 2016-11-01 21:36:17
通过将MySQL连接器从MySql.Data.EntityFrameworkCore更改为SapientGuardian.EntityFrameworkCore.MySql解决了问题。然后使用默认命令执行所有迁移。
发布于 2016-10-26 05:59:48
就像你为了发展而做的一样。
您必须在应用程序启动期间调用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尚未实现迁移或脚手架。
https://stackoverflow.com/questions/40252056
复制相似问题