Database.Migrate() at start-up means the runtime identity must hold DDL rights, so any SQL injection or RCE can alter or drop schema. It also couples deployment to start-up: several scaled-out instances can try to migrate at once (EF Core 9+ takes a database lock to serialise this, but a long migration still blocks start-up and health checks), and a failed migration takes the app down with it. Instead I generate an idempotent script or a migration bundle (dotnet ef migrations bundle) in CI and run it once in the release stage under a separate migration identity with db_ddladmin, after a backup and an approval gate for production. Migrations are written to be backward compatible (expand, then contract) so the old and new app versions both work during rollout, and the runtime identity keeps only DML.
Checks the candidate connects deployment design to database permissions.
Last updated 23 Nov 2026.