Handling Mistakes and Avoiding Pitfalls

Learn how to handle mistakes and avoid pitfalls when working with the Code-First workflow.

Overview

It is common to run into some challenges while working with migrations and making changes to the data models. In this lesson, we’ll review tips for avoiding common mistakes when working with EF Core.

Removing a migration

At some point, you may discover that a previously added migration is not needed. We can remove any migration not applied to the database using the code sample below:

Press + to interact
dotnet ef migrations remove

This command removes the migration and reverts the model to a previous snapshot.

Note: It is good practice to avoid removing migrations applied to production databases. If a migration is removed, we can’t revert those migrations from the databases, which might break the assumptions made by subsequent migrations.

Reverting a migration

What happens to a migration applied to a database? Can it be removed? Yes, we can remove migrations by reverting to a previous migration. Let’s go through how to do this with ...

Get hands-on with 1400+ tech skills courses.