I have one DbContext and two databases, one for debugging / development (local) and one for production (online). I switch them with the appsetting.Development.json and appsettings.Production.json files.
Both just look like this:
{
"ConnectionStrings": {
"Default": "Server={myServer};Persist Security Info=False;User ID={MyUser};Password={myPassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}
So when I work on the Code and start it, it uses the localDb and when I publish it, it uses the other db.
Now when I change something in my Models I have always to delete the migration files, then do
dotnet ef migrations add InitialModel
and then
dotnet ef database update
after that delete the migrations file again, change the appsettings.Development.json entry to my online db and do the commands again.
So here are my questions:
Is there a way to choose what config should be used in the migration commands? Like:
dotnet ef migrations add InitialModel --config ProductionIs there a way to use the Migration Files with both databases so that I don't have to delete the migration files always?