What this thread does
Do first: generate dotnet ef migrations script 0 --idempotent --output migrations.sql using the target database provider, then inspect the SQL before deployment.
Short answer
As of November 2026, EF Core 10.0 LTS is this card's release baseline; command details follow current CLI documentation. Idempotent SQL checks migration history and executes missing revisions within the generated range. (applying migrations).
Choose / don't choose
- Idempotent artifact: choose for SQL review and databases at different recorded revisions sharing one provider and migration lineage; don't use one provider's SQL for another database engine.
- Known-state range: choose when every target's current revision is known and compatible with the selected starting point.
- SQLite: choose a script from the known current migration, or
dotnet ef database updatewhen it is unknown; SQLite lacks the procedural conditional logic needed for idempotent scripts (limitations).
Not for: Drizzle schema deployment; see drizzle-kit-push-or-generate-migrate-which-one-for-my-project.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
--idempotent / -i | Include for conditional migration-history guards | EF Core current CLI; provider-dependent | CLI |
--output / -o | migrations.sql in this example; omission writes standard output | EF Core current CLI | CLI |
<FROM> | 0 includes the first migration; default 0. A named starting migration is excluded from forward changes | EF Core current CLI | CLI, range guidance |
<TO> | Explicit target name/ID to freeze the endpoint; omission means last migration | EF Core current CLI | CLI |
--no-transactions | Omit to retain generated transaction statements; include only for a deliberate external transaction strategy | EF Core current CLI | CLI |
MigrationsHistoryTable() | Keep configured table/schema consistent across artifact generation and targets; default table __EFMigrationsHistory | Relational EF Core current docs | history table |
Order of operations
1. Inventory the oldest target revision and desired endpoint. Use 0 when an empty database is possible. A narrower start cannot supply earlier missing migrations merely because --idempotent is present. Generate separately for each provider (range guidance). 2. Review guarded DDL, data changes, transaction statements and provider batch separators. (strategy table). 3. The SQL Server generator checks whether the configured history table exists, then checks MigrationId absence for each forward migration's guarded commands (history generator). 4. Execute that missing migration's operations before its history insert. The pinned migrator appends the completion row after generated operations; preserve its order and transaction handling. Stop the SQL runner on failure rather than continue into the completion insert (migrator). 5. After successful application, compare the expected migration IDs with the target's history and inspect the affected schema. Reapplying may skip recorded migrations, but a history row alone does not prove arbitrary manual changes match the model (history).
Known failures and fixes
Diagnostic: There is already an object named '__EFMigrationsHistory' in the database.
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
There is already an object named '__EFMigrationsHistory' in the database. | A historical dotted-schema guard issue | Compare generated history identifiers and actual history table/schema. Use the current provider; inspect quoted identifiers before retrying | graemeenglish, October 6, 2017, current history configuration |
already exists | A broken migration step left objects that already exist | Compare missing migration ID with actual objects; restore/reconcile the incomplete migration before retrying. Never insert a history row solely to silence the error | tomasaschan, January 17, 2018, deployment caution |
SQL Server's idempotent support is evidenced by the pinned generator. Partial application and schema/history mismatch remain reasons to inspect execution semantics.
Missing
- Serialize deployment of scripts: current docs confirm raw SQL scripts do not acquire EF migration locking (deployment strategies)
- The linked source does not confirm: The old dotted-schema report was closed after a fix; it is a historical diagnostic clue, not a current universal defect.
- An exhaustive current provider support matrix was not established. SQL Server is covered here; SQLite explicitly cannot generate these scripts. For other providers, consult their own current migration generator and release documentation before choosing this artifact.
Checked
2026-11-12; EF Core 10.0 release notes, current CLI/applying/history/SQLite references, pinned SQL Server history and migrator sources, and dated graemeenglish/tomasaschan reports read. No migration or SQL commands executed.
Started from a post by @Microsoft, packaged by the editor. Original post