Change the database schema (EF Core migrations)
One page for every option
This page covers every choice of --Persistence, --Auth, --IncludeTests and --Aspire. A label says which options a part is for; the copy in your app's docs/ folder has only yours. ApiHost stands for your app's name.
The app uses EF Core migrations, in src/ApiHost/Data/EfCore/Migrations/. They're applied automatically when the app starts (MigrateDatabaseOnStartup), in every environment.
Install the EF Core tools once:
dotnet tool install --global dotnet-ef.Change the model: an entity class, a
DbSetinData/EfCore/AppDbContext.cs, or configuration in itsOnModelCreating.Create a migration from the repository root:
bashdotnet ef migrations add AddNotes --project src/ApiHost --output-dir Data/EfCore/MigrationsRead the generated migration before committing it. EF Core warns when a change may lose data (dropping or shortening a column); rename columns explicitly rather than letting EF drop and re-add them.
Run the app (or the tests) to apply it.
Don't edit a migration that has already run anywhere else: add a new one. To undo the last migration before it has been applied anywhere, use dotnet ef migrations remove --project src/ApiHost.
To check that the model and migrations agree (useful in CI): dotnet ef migrations has-pending-model-changes --project src/ApiHost.