Junior — Middle
Explain what the migration mechanism in Entity Framework Core is and how it is used to manage database changes.
sobes.tech AI
Answer from AI
The migration mechanism in Entity Framework Core allows managing changes to the database schema (creating, modifying tables, indexes, relationships) based on changes in the application's data models.
How it works:
- The developer modifies the models (entity classes).
- Using the command
Add-Migrationordotnet ef migrations add, a migration is created — a class describing the changes. - The command
Update-Databaseapplies the migrations to the database, synchronizing its structure with the models.
This allows:
- Versioning database changes.
- Automating schema updates during deployment.
- Rolling back changes if necessary.
Example commands:
dotnet ef migrations add AddNewColumnToUsers
dotnet ef database update