📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you introduce EF Core migrations to an existing production database that was managed by EF6 migrations or by hand?

Mid-Level Theory Intermediate

🎯 Key points

  • Map model to the existing schema exactly, checking precision, types and names
  • Baseline migration recorded as applied: empty Up, or generated Up plus a manual history row
  • Verify the next migration is empty
  • Schema compare against a restored production copy; rehearse in staging
  • EF6 __MigrationHistory kept for reference only
  • Idempotent scripts reviewed in the pipeline; no Database.Migrate at production start-up

⏱ 30-second answer

Scaffold or map the model to match the current schema exactly (watch decimal precision, column types, FK and index names that EF6 conventions produced). Create an initial EF Core migration and mark it as already applied without running it: either delete the generated body of Up/Down so the baseline is empty, or keep the generated code (useful for creating new dev databases) and insert its row into __EFMigrationsHistory on existing databases. Verify with a schema compare (SqlPackage/DACPAC or a migration script against a restored copy of production) that model and database match and that the next migration is empty. Rehearse the whole process in staging first. Keep the old EF6 __MigrationHistory table only for reference, never as a source of truth. From then on generate idempotent SQL scripts (dotnet ef migrations script --idempotent) that are reviewed and run by the pipeline, not by Database.Migrate() at start-up.

🔍 What the interviewer is checking

Checks they can baseline a schema without destructive changes

↩ Usually asked after

More in Legacy Technologies

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me