Base solution for your next web application
Open Closed

How can i update migration on Server Production? #9503


User avatar
0
sempus created

Hi, When I have successfully deployed to the server Production. But after a while, I need to redeploy and update the database (ex: Table structure changes). So then, how do we get the migration to run automatically when rebuilding my app? I'm using Version 8.7.0 : Angular + .Net Core 3

Thanks


1 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Refer to the practice of vNext, you can use the MigrateAsync method provided by DbContext to migrate. e.g.

    var dbContext = _serviceProvider.GetRequiredService<XXDbContext>();
    await dbContext
        .Database
        .MigrateAsync();
    
    // or
    
    var migrator = dbContext.Database
        .GetInfrastructure()
        .GetService<IMigrator>()
        .MigrateAsync("targetMigration");
    

    If you are a production database, this is not recommended. Please use dotnet-ef to generate the migration script, confirm that there is no problem with the SQL, and then upgrade.