Entity Framework Core Interview Question #15

What is the difference between Add-Migration and Update-Database?

EF Core Fundamentals & DbContext Junior Beginner

Quick Interview Answer

Add-Migration compares the current EF Core model with the previous model snapshot and creates migration code describing the detected schema changes. It does not normally apply those changes to the database.

Detailed Explanation

Add-Migration compares the current EF Core model with the previous model snapshot and creates migration code describing the detected schema changes. It does not normally apply those changes to the database.

Update-Database applies pending migrations to the selected database.

In Visual Studio Package Manager Console, these commands are commonly used during development. Production environments often apply reviewed migrations through a controlled deployment process.

Code Example

# Package Manager Console
Add-Migration AddProductCategory
Update-Database