Entity Framework Core Interview Question #76
What is the purpose of EF Core migrations?
Migrations, Database Schema & Data Management Mid-Level Intermediate
Quick Interview Answer
EF Core migrations provide a versioned way to evolve a relational database schema as the application's EF Core model changes. A migration can describe operations such as creating or dropping tables, adding or altering columns, creating indexes, and changing constraints.
Detailed Explanation
EF Core migrations provide a versioned way to evolve a relational database schema as the application's EF Core model changes. A migration can describe operations such as creating or dropping tables, adding or altering columns, creating indexes, and changing constraints.
Migrations help keep schema changes in source control alongside application code. Each migration represents a step from one known model state to another.
Generated migrations should be reviewed before they are applied, especially in production, because a model change can produce expensive, blocking, or destructive database operations.
Code Example
# Package Manager Console
Add-Migration AddProductInventory
# Apply pending migrations
Update-Database