Adding the Initial Migration

Open a PowerShell Command Prompt and navigate through the project’s root folder, which is as follows in our example:

C:ProjectsTestMakerFreeTestMakerFreeWebApp

Once there, type the following command to add the first migration:

dotnet ef migrations add "Initial" -o "DataMigrations"

The optional -o parameter can be used to change the location where the migration code-generated files will be created; if we don’t specify it, a root-level /Migrations/ folder will be created and used as default. Since we put all the EntityFrameworkCore classes into the /Data/ folder, it’s advisable to store migrations there as well.

The command should give the on-screen output below:

Wait for the migration to be created, and then type the following to apply it:

dotnet ef database update

Once done, open the Server Object Explorer and verify that the TestMakerFree Database has been created, along with all the relevant tables:

If you've used migrations before, you might be asking why we didn’t use the Visual Studio’s Package Manager Console to execute these commands. The reason is simple--unfortunately, doing this won’t work, because the commands need to be executed within the project root folder, which is not where the Package Manager Console commands are executed. It is also unknown whether that behavior will change in the near future.

If we go back to Visual Studio and take a look at our project's Solution Explorer, we can see that there’s a new /Data/Migrations/ folder containing the EF Core code-generated files.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.131.212