{"record":{"id":"ac701f7f849ab274","repo":"dotnet/efcore","slug":"metadata-model-returned-should-not-be-null-prov","errorCode":null,"errorMessage":"Metadata model returned should not be 'null'. Provider: {providerTypeName}.","messagePattern":"Metadata model returned should not be 'null'\\. Provider: (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs","lineNumber":103,"sourceCode":"        }\n        else if (!codeOptions.SuppressOnConfiguring)\n        {\n            _reporter.WriteWarning(DesignStrings.SensitiveInformationWarning);\n        }\n\n        codeOptions.ConnectionString ??= connectionString;\n\n        var databaseModel = _databaseModelFactory.Create(resolvedConnectionString, databaseOptions);\n        var modelConnectionString = (string?)databaseModel[ScaffoldingAnnotationNames.ConnectionString];\n        if (!string.IsNullOrEmpty(modelConnectionString))\n        {\n            codeOptions.ConnectionString = modelConnectionString;\n        }\n\n        var model = _factory.Create(databaseModel, modelOptions);\n        if (model == null)\n        {\n            throw new InvalidOperationException(\n                DesignStrings.ProviderReturnedNullModel(\n                    _factory.GetType().ShortDisplayName()));\n        }\n\n        if (string.IsNullOrEmpty(codeOptions.ContextName))\n        {\n            var annotatedName = model.GetDatabaseName();\n            codeOptions.ContextName = !string.IsNullOrEmpty(annotatedName)\n                ? _code.Identifier(annotatedName + DbContextSuffix)\n                : DefaultDbContextName;\n        }\n\n        var codeGenerator = ModelCodeGeneratorSelector.Select(codeOptions);\n\n        return codeGenerator.GenerateModel(model, codeOptions);\n    }\n\n    /// <summary>","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs#L85-L121","documentation":"Thrown in ReverseEngineerScaffolder.ScaffoldModel (line 103, resource ProviderReturnedNullModel) when the ScaffoldingModelFactory returns a null IModel after reading the database model. The factory (_factory.Create(databaseModel, modelOptions)) is expected to always produce a model; null indicates the provider's scaffolding factory failed to translate the database model, which EF treats as a provider/tooling defect rather than a user config error.","triggerScenarios":"After _databaseModelFactory.Create succeeds, _factory.Create(databaseModel, modelOptions) returns null. The `if (model == null)` guard throws ProviderReturnedNullModel(factory.GetType().ShortDisplayName()). The provider's ScaffoldingModelFactory bailed without producing a model.","commonSituations":"A database the provider cannot reverse-engineer (unsupported schema constructs, exotic types, empty/no tables selected). A version mismatch between the EF Core Design package and the provider package causing the factory to return null. A misconfigured/custom ScaffoldingModelFactory. Provider bugs for specific DB objects.","solutions":["Align versions of Microsoft.EntityFrameworkCore.Design and the database provider package (they must match the runtime major version).","Adjust DatabaseModelFactoryOptions (tables/schemas filter) to exclude objects the provider cannot handle and isolate the trigger.","Upgrade the provider to the latest patch; provider bugs causing null models are often fixed.","If you supply a custom ScaffoldingModelFactory, ensure Create never returns null; return an empty model or throw a meaningful exception instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// After creating the database model, guard the factory result\nvar model = factory.Create(databaseModel, modelOptions);\nif (model is null)\n    throw new InvalidOperationException($\"Provider {factory.GetType()} returned a null model.\");","typeGuard":null,"tryCatchPattern":"try { scaffolder.ScaffoldModel(...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Metadata model returned should not be null\"))\n{ /* align Design + provider versions, narrow table selection, upgrade provider, then retry */ }","preventionTips":["Pin matching major versions of Microsoft.EntityFrameworkCore.Design and the provider package.","Narrow DatabaseModelFactoryOptions to well-supported tables when reverse-engineering.","Keep provider packages up to date.","Custom ScaffoldingModelFactory implementations should never return null."],"tags":["ef-core","scaffolding","reverse-engineer","provider","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}