Tutorials Entity Framework Core Tutorial
Migrations in EF Core — Complete Guide
Migrations in EF Core — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.
On this page
Entity Framework Core Tutorial · Lesson 15 of 100
Migrations in EF Core
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Foundations · ~6 min · Module 2: Code First Approach
What is this?
Migrations are timestamped C# files describing schema changes — CreateTable, AddColumn, AddForeignKey. You create them with dotnet ef migrations add after model changes.
Why should you care?
Every ShopNest environment applies the same ordered migration history so dev, QA, and production schemas match.
See it live — copy this example
Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).
dotnet ef migrations add InitialShopNest \
--project ShopNest.Infrastructure \
--startup-project ShopNest.Api
# Creates Migrations/20250719120000_InitialShopNest.cs + snapshot
What happened?
- InitialShopNest captures current model diff vs empty database.
- Designer and snapshot files let EF compute the next diff.
- Timestamp prefix orders history.
Practice next
- Ensure DbContext and entities compile cleanly.
- Run migrations add with correct --project and --startup-project paths.
- Read Up() in plain English before database update.
- Run dotnet ef migrations script to preview full SQL without applying.
- Add a second migration after adding Order entity and diff the two Up() methods.
Remember
migrations add snapshots model changes. Review Up() SQL before apply. Never edit applied migrations — add a new one instead.
ShopNest release train
Release 2.3 ships AddOrderStatus migration reviewed by DBA before production apply.
Outcome: All regions apply identical schema steps from __EFMigrationsHistory.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!