2.1: Add Migration and Database
Referencing Entity Framework Core CLI Tool
Now we will add a package to allow us to use Entity Framework Core and run migrations with the CLI.
In your terminal - navigate to EFConnect.Data
and run the following commands to update the EFConnect.Data.csproj
file:
Ensure your updated EFConnect.Data.csproj
file roughly matches the following (versions of packages may be different:
Restore your packages:
Note: you may get strange error messages about a downgraded version:
error NU1605: EFConnect.Data -> Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.2 -> Microsoft.NETCore.App (>= 2.0.6
If that's the case, specify the RuntimeFrameworkVersion
to match the error (in this case 2.0.6:
Verify that the Entity Framework Core CLI tools were installed correctly:
You should get a unicorn some some help information. Feel free to explore that.
Running Our First Migration
Let's run our first migration.
In your EFConnect.Data
folder, run the following command:
We added an option (-s
) to tell Entity Framework Core the location of our Startup
project - since our .Data
project is separate from our .API
project.
This blog post provided a solution to the above problem. Read it if you would like to understand in-depth.
Creating Our Database
To create our database (or to update the database with a migration in the future) we'll run this command:
We won't run it now, but it's good to have this command in your back pocket incase you run into issues.
This removes the latest migration:
Last updated