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

BeginnerIntermediateAdvancedProfessional

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

  1. Ensure DbContext and entities compile cleanly.
  2. Run migrations add with correct --project and --startup-project paths.
  3. Read Up() in plain English before database update.
  4. Run dotnet ef migrations script to preview full SQL without applying.
  5. 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.

Mid PDF Detailed
What are migrations?
Short answer: How are they used in Code First? Migrations in EF Core are a way to: Track schema changes over time Apply those changes to the database 📦 Basic commands: Add-Migration MigrationName Update-Database Remove-…
Mid PDF Detailed
What are migrations?
Short answer: Migrations in EF Core are a way to: Track schema changes over time Apply those changes to the database 📦 Basic commands: Add-Migration MigrationName Update-Database Remove-Migration Script-Migration 🔄 Mig…
Mid PDF Detailed
How to apply migrations to the database? (e.g. Update-Database)
Short answer: pply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them against the database.…
Mid PDF Detailed
How to apply migrations to the database?
Short answer: (e.g. Update-Database) Apply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes th…
Mid PDF Detailed
How do you seed initial data using migrations / EF Core configuration?
Short answer: Use the HasData() method in OnModelCreating(): modelBuilder.Entity<User>().HasData( new User { Id = 1, Name = "Admin" } ); Data is inserted automatically during Update-Database. Changes to s…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Entity Framework Core Tutorial
Course syllabus

Entity Framework Core Tutorial

Module 1: EF Core Fundamentals
Module 2: Code First Approach
Module 3: CRUD Operations
Module 4: LINQ
Module 5: Relationships
Module 6: Advanced EF Core
Module 7: Performance Optimization
Module 8: Enterprise Architecture
Module 9: Testing & Debugging
Module 10: Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details