{"record":{"id":"7f44a87af7fa3189","repo":"dotnet/efcore","slug":"changes-have-been-made-to-the-model-since-the-last","errorCode":null,"errorMessage":"Changes have been made to the model since the last migration. Add a new migration.","messagePattern":"Changes have been made to the model since the last migration\\. Add a new migration\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"warning","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":375,"sourceCode":"\n        return files;\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual void HasPendingModelChanges(string? contextType)\n    {\n        using var context = _contextOperations.CreateContext(contextType);\n\n        var hasPendingModelChanges = context.Database.HasPendingModelChanges();\n\n        if (hasPendingModelChanges)\n        {\n            throw new OperationException(DesignStrings.PendingModelChanges);\n        }\n\n        _reporter.WriteInformation(DesignStrings.NoPendingModelChanges);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    [RequiresDynamicCode(\"Runtime migration compilation requires dynamic code generation.\")]\n    public virtual MigrationFiles AddAndApplyMigration(\n        string name,\n        string? outputDir,\n        string? contextType,\n        string? @namespace,\n        string? connectionString)","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L357-L393","documentation":"HasPendingModelChanges detected that the current model differs from the last migration's model snapshot, i.e. you have unbilled model changes. This is thrown by 'dotnet ef migrations has-pending-model-changes' (used in CI guards) to signal non-zero exit. It is informational in nature but reported as an OperationException so the CLI exits non-zero.","triggerScenarios":"'dotnet ef migrations has-pending-model-changes' runs HasPendingModelChanges() which returns true because entity/property/config changes since the last migration are not yet captured in a migration.","commonSituations":"CI pipeline checks for drift after a model edit; developer added an entity or property but forgot 'migrations add'; snapshot out of sync after a merge.","solutions":["Run 'dotnet ef migrations add <Name>' to capture the pending changes.","If the changes are unintended, revert the model edit and rebuild.","If a previous migration was applied but its snapshot is stale, regenerate the snapshot by adding an empty migration or hand-fixing ModelSnapshot.","In CI, treat this exit code as a gate that requires a new migration commit."],"exampleFix":"// before: CI fails because model changed\nentity.Property<string>(e => e.Status); // newly added\n// after\ndotnet ef migrations add AddOrderStatus","handlingStrategy":"try-catch","validationCode":"bool hasPending = context.Database.HasPendingModelChanges();\nif (hasPending) Console.Error.WriteLine(\"Model drift detected -- add a migration.\");","typeGuard":null,"tryCatchPattern":"try { executor.HasPendingModelChanges(contextType); }\ncatch (OperationException ex) when (ex.Message.Contains(\"Changes have been made\"))\n{ /* CI gate: fail the build and prompt for a new migration */ Environment.ExitCode = 1; }","preventionTips":["Wire 'has-pending-model-changes' into CI as a required gate.","Add migrations immediately after model changes, not in batches.","Resolve snapshot conflicts during merges before pushing."],"tags":["efcore","migrations","ci","model-snapshot","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}