Tutorials Entity Framework Core Tutorial

Update Database with EF Core Migrations

Update Database with EF Core Migrations: 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 16 of 100

Update Database with EF Core Migrations

BeginnerIntermediateAdvancedProfessional

Beginner · 1 — Foundations · ~6 min · Module 2: Code First Approach

What is this?

dotnet ef database update applies pending migrations to a target database, executing each Up() method and recording names in __EFMigrationsHistory.

Why should you care?

When a teammate pulls new ShopNest migrations, they run database update so LocalDB matches yours before testing checkout.

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 database update \
  --project ShopNest.Infrastructure \
  --startup-project ShopNest.Api

# Roll back one step in dev only:
dotnet ef database update AddCategories \
  --project ShopNest.Infrastructure \
  --startup-project ShopNest.Api

What happened?

  • update runs all pending migrations in order.
  • Rolling back to a prior name executes Down() methods — use cautiously outside dev.

Practice next

  1. Run database update against LocalDB ShopNest database.
  2. Open SSMS and confirm Products and __EFMigrationsHistory tables.
  3. Simulate new teammate: clone repo, restore, update, verify CanConnectAsync.
  4. Run dotnet ef migrations list to see applied vs pending.
  5. Target a different connection with --connection for a staging smoke test.

Remember

database update applies pending migrations. __EFMigrationsHistory tracks applied names. Rollback is a dev convenience, not a production habit.

ShopNest onboarding database

New developer runs dotnet ef database update and gets full schema plus seed from migrations.

Outcome: Fifteen-minute setup instead of restoring a mystery .bak file.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

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…
Junior PDF Detailed
How do you write a basic CRUD operation (Insert / Update / Delete / Read) in EF Core?
Short answer: // Create context.Users.Add(new User { Name = "John" }); context.SaveChanges(); // Read var user = context.Users.FirstOrDefault(u => u.Id == 1); // Update user.Name = "Jane"; context.…
Junior PDF Detailed
What is Database First approach?
Short answer: Database First involves generating C# entity classes and a DbContext from an existing database. ✅ Pros: Quick start if the DB already exists Ensures model aligns with legacy databases ❌ Cons: Harder to vers…
Junior PDF Detailed
What is Database First approach?
Short answer: Use‑cases and pros and cons Database First involves generating C# entity classes and a DbContext from an existing database. ✅ Pros: Quick start if the DB already exists Ensures model aligns with legacy data…
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