Creating a database with EF Core migrations
EF Core allows you to create and modify the database and its schema from your code. To enable this feature, EF Core maintains the database structure, and the changes between each schema version, in classes that are generated by the EF Core Tools. After an instance of your DbContext
is created, you can instruct it to migrate to the newest schema version.
To enable EF Core migrations in your application, you need to install the EF Core Tools by adding the Microsoft.EntityFrameworkCore.Tools
NuGet package if it's not already installed (if you're using the Microsoft.AspNetCore.All
meta-package, then you already have it installed).Â
Â
Creating a new migration
Every time your model changes, you need to add a new migration to your project. Follow these steps to learn how to do this::
- Open the Package Manager Console (
Tools |Â
NuGet Package Manager |Â
Package Manager Console
). - Type and run the following command:
Add-Migration [Migration Name] -p [Project Name...