{"record":{"id":"ab537592482752b4","repo":"dotnet/efcore","slug":"the-data-insertion-operation-on-table-is-not-a","errorCode":null,"errorMessage":"The data insertion operation on '{table}' is not associated with a model. Either add a model to the migration, or specify the column types in all data operations.","messagePattern":"The data insertion operation on '(.+?)' is not associated with a model\\. Either add a model to the migration, or specify the column types in all data operations\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs","lineNumber":893,"sourceCode":"            throw new InvalidOperationException(\n                RelationalStrings.InsertDataOperationValuesCountMismatch(\n                    operation.Values.GetLength(1), operation.Columns.Length,\n                    FormatTable(operation.Table, operation.Schema ?? model?.GetDefaultSchema())));\n        }\n\n        if (operation.ColumnTypes != null\n            && operation.Columns.Length != operation.ColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.InsertDataOperationTypesCountMismatch(\n                    operation.ColumnTypes.Length, operation.Columns.Length,\n                    FormatTable(operation.Table, operation.Schema ?? model?.GetDefaultSchema())));\n        }\n\n        if (operation.ColumnTypes == null\n            && model == null)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.InsertDataOperationNoModel(\n                    FormatTable(operation.Table, operation.Schema ?? model?.GetDefaultSchema())));\n        }\n\n        var propertyMappings = operation.ColumnTypes == null\n            ? GetPropertyMappings(operation.Columns, operation.Table, operation.Schema, model)\n            : null;\n\n        for (var i = 0; i < operation.Values.GetLength(0); i++)\n        {\n            var modificationCommand = Dependencies.ModificationCommandFactory.CreateNonTrackedModificationCommand(\n                new NonTrackedModificationCommandParameters(\n                    operation.Table, operation.Schema ?? model?.GetDefaultSchema(), SensitiveLoggingEnabled));\n            modificationCommand.EntityState = EntityState.Added;\n\n            for (var j = 0; j < operation.Columns.Length; j++)\n            {\n                var name = operation.Columns[j];","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L875-L911","documentation":"To generate SQL for an InsertDataOperation EF needs the column types. It can get them from the attached model (via property mappings) or from the operation's explicit ColumnTypes. If neither is present — ColumnTypes is null AND the model passed to Generate is null — there is no way to infer how to render the values, so it throws.","triggerScenarios":"An InsertDataOperation is built without a model context (e.g. operations applied directly via migrationBuilder without a snapshot) and ColumnTypes was not set. Common when invoking Generate on a standalone list of operations or running a hand-authored migration that omits both the model and column types.","commonSituations":"Building migration commands at runtime from raw operations; applying operations through a custom pipeline that does not pass the model; removing column types while also detaching the model in tests.","solutions":["Supply columnTypes for every InsertData operation when no model is available.","Pass the target IModel into the migrator/Generate call so EF can map columns to properties.","Regenerate the migration so the model snapshot is wired up automatically."],"exampleFix":"// before — no model, no types\nvar op = new InsertDataOperation\n{\n    Table = \"Products\",\n    Columns = new[] { \"Id\", \"Name\" },\n    Values = new object[,] { { 1, \"A\" } }\n};\n// generator.Generate(new[] { op }, model: null, ...) -> throws\n\n// after — supply column types\nvar op = new InsertDataOperation\n{\n    Table = \"Products\",\n    Columns = new[] { \"Id\", \"Name\" },\n    ColumnTypes = new[] { \"int\", \"nvarchar(100)\" },\n    Values = new object[,] { { 1, \"A\" } }\n};","handlingStrategy":"validation","validationCode":"// Ensure InsertData can resolve types: model present OR columnTypes set\nstatic void ValidateInsertModelOrTypes(InsertDataOperation op, IModel? model)\n{\n    if (op.ColumnTypes == null && model == null)\n        throw new ArgumentException(\n            $\"InsertData on {op.Table} has no model and no columnTypes; \" +\n            \"cannot infer SQL types.\");\n}","typeGuard":"static bool InsertTypesResolvable(InsertDataOperation op, IModel? model)\n    => op.ColumnTypes != null || model != null;","tryCatchPattern":null,"preventionTips":["Always pass the target IModel when generating commands from raw operations.","If operating without a model, populate ColumnTypes for every InsertData.","Avoid hand-constructing InsertDataOperation at runtime; prefer the model + HasData flow."],"tags":["migrations","sql-generation","data-integrity","seeding","model"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}