1
votes

I currently have an ASP.NET Core 2.0 project and I've just implemented code first migrations to the localdb and have around 3 migrations including the initial create. I'm wondering what the correct process is to change to a new database? Is it simply a case of updating the connection string and running the below in the project directory?

dotnet ef database update

My current knowledge is based on the below Microsoft tutorial and I've been using the CLI commands. https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations

2
what you have tried? - lazydeveloper
@lazydeveloper I haven't tried the above yet as I'm concerned it will mess up what currently works. I'm confident changing the connection string, just unsure how to ensure the current migrations are replicated in the new database. I've used initial create and update on the existing database so I'm comfortable with making changes to the existing database. - Mihto
change connectionString and run command for initial create. As it is CodeFirst, changes will reflected. - lazydeveloper

2 Answers

0
votes

In answer to my own question, it does appear that running the following command in the existing project directory will build a new database from scratch including all the existing migrations. As long as you update the connection string to the new database and have already implemented migrations on the existing database.

dotnet ef database update
0
votes

correct process is to change to a new database

Everything depends what you mean by writing this sentence ( I am not sure what "new database" means in it) altough flow looks like this: 1. First you make initial create 2. Then you change something in your code (create some additional fields etc) 3. Then you write "dotnet ef database update" command in CLI to update your current database.