Forbes India Leader Recognition
e.preventDefault(); // Prevent form submission input.blur(); // remove focus input.value = ""; // optional: clear the input

Migrations In Entity Framework Core

Migrations In Entity Framework Core

Featured Image

A Brief Intro  About Entity Framework Core (EF Core)

Entity Framework Core is an ORM (object relational mapper) which can be used to access data from various data sources. Entity Framework was the initial framework which was part of classic .NET Framework (predecessor of .NET Core). Entity Framework Core is the open source, cross platform version of Entity Framework.

Entity Framework Core Migrations

Entity Framework Core provides a way to communicate with data stores using C# objects.

Earlier, database creation, tables creation, seed data population were done using SQL scripts. The need of scripts are eliminated by Entity Framework Core..

We can create a custom DbContext implementation for creating a database, that will specify list of DbSets (a DbSet basically maps to table from relational database). DbSet is  generic type, it accepts  POCO class as type parameter. This POCO class specify public properties and these properties are columns of the SQL table. These set of classes are commonly known as EF Core Model.

We can generate migrations using Entity Framework Core Tool. A migration is a script that is generated to keep the database in sync with the DbContext code. A migration is  used to incrementally apply schema changes to database so as to keep database compatible with EF Core model.

When you generate the migration script, a new C# file is generated. It’s name has date and timestamp indicating when this file was generated. The file contains C# code to apply schema changes.

There are two ways to generate migrations

  • Using dotnet CLI tools (this is recommended approach for .NET Core apps)
  • By Using NuGet package manager console  which is used for EF6 – .NET Framework like experience or for working from Visual Studio Package Manager.

In this blog, we are going to look at  dotNET CLI  tools and commands to generate and apply migrations.

The dotnet CLI  provides entity framework tool which is  used for creating migration. In the below  code snippet, the first command is used to install the tool and second command is used to update the already installed tool.

## For installing the dotnet CLI ef tool
dotnet tool install –global dotnet-ef
## For updating already existing tool
dotnet tool update –global dotnet-ef
## The project which contains EF Core Models
## Should have reference to this package
## For using EF Migration commands using above tool
dotnet add package Microsoft.EntityFrameworkCore.Design

Common Commands

This tool can be used for following purposes mentioned below:

  • For creating new migration– this is used to generate new migration file
  • For removing an existing migration – this is used to remove (delete) the migration file.
  • For applying migrations to a database – this is used for creating new or altering existing database
  • For removing existing database – this is used for dropping existing database

The below code snippet shows all these commands. These commands can be very helpful when we are working on creating a new database using entity framework.

## For the commands Given Below,
## TestDbContext – This is a class which is derived from DbContext
## For deleting an existing database
dotnet ef database update 0 –context TestDbContext
## For removing an existing migrations
dotnet ef migrations remove –context TestDbContext
## For creating a new EF migration, with name InitialCreate
dotnet ef migrations add InitialCreate –context TestDbContext
## For applying migrations to the database
## All tables specified in SampleDbContext will be created in the database
dotnet ef database update –context TestDbContext

Related Posts

Latest Posts

  • All Posts
  • AI Powered Knowledge
  • ai/ml
  • CEO India Magazine
  • CMMI level 5 Certification
  • e-learning
  • Fintech
  • gaming
  • Generative AI
  • healthcare
  • manufacturing
  • News
  • OTT
  • Portfolio
  • supply chain
  • travel and hospitality
  • Tudip's AI Hackathon
  • Voxlearn Enterprises
    •   Back
    • Android
    • iOS
    • Java
    • PHP
    • MEAN
    • Ruby
    • DotNet
    • IoT
    • Cloud
    • Testing
    • Roku
    • CMS
    • Python
The Future of Workplace Learning: AI-Powered Knowledge on Demand

The Future of Workplace Learning: AI-Powered Knowledge on Demand

June 12, 2026

A few months ago, I was sitting in a meeting with a team lead who looked genuinely frustrated. Not because…

Read More
We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

We Did It Again: Tudip Successfully Renews Its CMMI Level 5 Certification

June 9, 2026

Nobody around here needed a memo to know something worth celebrating had happened. The message from the CMMI Institute said…

Read More
CEO India Magazine Features Dipti Agrawal: The Woman Behind Intelligent Enterprise Solutions

CEO India Magazine Features Dipti Agrawal: The Woman Behind Intelligent Enterprise Solutions

June 9, 2026

There are moments at work that just stop you in your tracks. Not the big quarterly reviews or the product…

Read More

India

Plot No. 11/2, Phase 3, Hinjewadi Rajiv Gandhi Infotech Park, Pune, India – 411057.
info@tudip.com
+91-96-8990-0537

United States

1999 S. Bascom Ave Suite 700, Campbell CA. 95008, USA.
info@tudip.com
+1-408-216-8162

Canada

64 Caracas Road North York, Toronto Ontario M2K 1B1, Canada.
info@tudip.com

Mexico

Calle Amado Nervo #785 Interior B Colonia Ladron De Guevara 44600 Guadalajara, Jalisco, Mexico.
info@tudip.com

Singapore

77 High Street, #10-12B High Street Plaza, Singapore 179433.
info@tudip.com

Colombia

Cra. 9 # 113-53 Of. 1405 Bogotá D.C., Colombia.
info@tudip.com

UAE

Tudip Information Technologies L.L.C Office No 109, ABU HAIL BUILDING 13, Abu Hail, Dubai, UAE.
info@tudip.com

Nigeria

22 Kumasi Crescent, Wuse 2, Abuja, Nigeria.
info@tudip.com