What are the best practices for managing EF Core Migrations in CI/CD pipelines?
Updated Apr 28, 2026
Short answer
Migrations should be applied via Idempotent SQL scripts generated by EF Core or specialized migration tools, not by calling Database.Migrate() on startup.
Deep explanation
Calling Database.Migrate() on app startup causes race conditions if multiple instances start simultaneously (e.g., Kubernetes horizontal scaling). Best practice is using dotnet ef migrations script --idempotent in the CI phase to generate a SQL script. The CD pipeline then executes this script against the production DB using a tool like Flyway or DBUp before the new application pods are started.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro