Why Migrations?
Your model changes over time: you add a column, rename a table, add an index. A migration is a small C# file that describes one change in a way EF can apply to the database and also undo. Together they form the history of your schema.
Create the First Migration
| Command | What it does |
|---|---|
migrations add <Name> | Compares your model with the last snapshot and creates a migration file |
database update | Applies all pending migrations to the database |
migrations list | Shows migrations and whether they were applied |
migrations remove | Deletes the last migration (if not yet applied) |
migrations script | Creates a SQL script instead of changing the database |
A Migrations folder appears with ..._InitialCreate.cs and LibraryContextModelSnapshot.cs.
Change the Model
The new migration contains an AddColumn operation. Open it and read it every time. It is short and shows exactly what will happen.
Peek Inside a Migration
Go Back
Deploying to Production
| Approach | Notes |
|---|---|
| SQL script (recommended) | dotnet ef migrations script --idempotent -o update.sql creates a script that can be reviewed and run safely multiple times |
| Migration bundle | dotnet ef migrations bundle creates a single executable for your pipeline |
| Migrate at app startup | db.Database.Migrate(). Convenient for small apps, risky with several servers starting together |
RenameColumn before applying it.
Seed Data
Migrations folder with your code so everyone, and the build server, gets the same schema history.
Conclusion
Change the model, run migrations add, read the generated code and apply it with database update. For production prefer reviewed SQL scripts or bundles.

