Code-First ASP.Net Core 2.0 프로젝트에서 Entity Framework Core 2.0을 사용하여 프로그래밍 방식으로 마이그레이션을 적용하려고합니다. 터미널을 통해 수동으로 마이그레이션을 실행하면 문제없이 적용됩니다. 내 Startup
클래스에 마이 그 레이션을 적용해도 데이터베이스 모델은 변하지 않습니다.마이그레이션이 적용되지 않습니다.
내가 잘못 했나요?
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFrameworkSqlite();
services.AddDbContext<ApplicationContext>(options => options.UseSqlite("Data Source=blogging.db"));
services.AddDbContext<UserContext>(options => options.UseSqlite("Data Source=blogging.db"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
var services = app.ApplicationServices.GetService<IServiceScopeFactory>();
var context = services.CreateScope().ServiceProvider.GetRequiredService<ApplicationContext>();
context.Database.Migrate();
}
내가 터미널에서이 작업을 실행할 수 있으며 잘 작동
:
후에 .NET EF 마이그레이션은 EFCore_Test.DataAccess.ApplicationContext
내가 여러 DataContext
유형이 --context FourthMigration를 추가; 하나만 전체 데이터 모델을 나타내고 나머지는 더 많은 도메인 특정 매너에있는 데이터베이스에 액세스하는 데 사용됩니다. ApplicationContext
은 내 모든 "부엌 싱크"데이터 컨텍스트를 나타냅니다. 마이그레이션 및 업데이트를 수행하는 것은이 컨텍스트입니다.
Azure 로의 배포를 준비하면서, 나는 닷넷 코어 툴링 명령을 실행하기 위해 powershell 스크립트를 연결하는 대신 각 배포시 자체적으로 웹 응용 프로그램을 마이그레이션하고 싶습니다.