1
votes

So I have an EF Core project. When I need to add/migrations I issue and update command:

dotnet ef database update -v

This all works fine, if I need to update the QA, Staging, Prod database I update the connection string in my appsettings.json file and run the command.

What happens if I don't have access to production from my local machine? How do you go about updating the database to the latest migration?

If I remember working with Entity Framework (not .net core). It would try and update the database automatically when I deploy a new version of the .net application. Does this functionality still exist in .NET core?

1

1 Answers

2
votes

Yes you could run

dbContext.Database.Migrate();

On startup but it is generally not a good idea to conflate database migration with your application lifecycle - best practice is to keep your application start up as fast and simple as possible because an application start failure is hard to diagnose remotely, and a migration would introduce a lot of unwelcome complexity.

The alternative is to run a migration operation as part of your deployment. It depends on what method you use to deploy but say for example you use a CI server, you will be able to run

dotnet ef database update

after copying the new code but before starting the application back up.