This video is available to students only

Adding our First Migration

In this lesson, we'll be making our first migration

Making our first migration#

In the last lesson, we added Entity Framework Core to our project. If we go back, we named our table Courses since this is going to have all our course related properties. If we go to our Course entity class, this is going to be our table columns. This is not the final version, we'll be making changes as we move along.

Now to make the database appear in our project, we'll have to make a migration. Since we're talking about migration, let me remind you that we are using code first approach because of which Entity Framework Core is responsible for transforming your properties into a database table. Now to make a migration, we'll have to go back to our terminal. Let's go back from API project to the root of the project. To make migrations, we need to have entity framework tools. Let's see if I have. Type dotnet tool list --global

Check if you have dotnet ef tools:

As you can see, my tool list containes dotnet ef. If you don't have it, go to Dotnet EF Page. You can see the command we need to install the tool. Make sure it matches your runtime or it will you show you a warning. Now copy this command to your clipboard, go to the terminal and run this command. To me, it says dotnet-ef is already installed. You won't see it if you're running this command for the first time. You can use the same command to update the tool; just replace install with update. I won't do it since I'm using the latest version. Let's run dotnet tool list --global again; if it's correctly installed, you will see dotnet-ef listed as mine. To check which features dotnet ef tool provides us, type dotnet ef -h; on top, you would see Options, out of which, we already selected -h. If you look at Commands, we can manage database, dbcontext and migrations using the tool.

Check the available options:

Start a new discussion. All notification go to the author.