{"record":{"id":"dc4b160bf1ed2af9","repo":"dotnet/efcore","slug":"the-data-modification-operation-on-table-is-no","errorCode":null,"errorMessage":"The data modification 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 modification 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":1098,"sourceCode":"            && operation.KeyColumns.Length != operation.KeyColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationKeyTypesCountMismatch(\n                    operation.KeyColumnTypes.Length, operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.ColumnTypes != null\n            && operation.Columns.Length != operation.ColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationTypesCountMismatch(\n                    operation.ColumnTypes.Length, operation.Columns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.KeyColumnTypes == null\n            && model == null)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationNoModel(\n                    FormatTable(operation.Table, operation.Schema)));\n        }\n\n        var keyPropertyMappings = operation.KeyColumnTypes == null\n            ? GetPropertyMappings(operation.KeyColumns, operation.Table, operation.Schema, model)\n            : null;\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.KeyValues.GetLength(0); i++)\n        {\n            var modificationCommand = Dependencies.ModificationCommandFactory.CreateNonTrackedModificationCommand(\n                new NonTrackedModificationCommandParameters(operation.Table, operation.Schema, SensitiveLoggingEnabled));\n            modificationCommand.EntityState = EntityState.Modified;\n\n            for (var j = 0; j < operation.KeyColumns.Length; j++)","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L1080-L1116","documentation":"Thrown inside GenerateModificationCommands(UpdateDataOperation, ...) in src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs:1098 (message key UpdateDataOperationNoModel). EF needs a type mapping for both the key columns (WHERE clause) and the updated columns (SET clause). It gets these from the model or from explicit type arrays; the code specifically checks the KEY side: when KeyColumnTypes == null && model == null it throws InvalidOperationException (the SET side is then also unreachable).","triggerScenarios":"Calling migrationBuilder.UpdateData on a table not mapped to any entity, in a model-less migration, without supplying keyColumnTypes:. Also when migrations are applied through a code path that passes model == null while the migration contains UpdateData. Note: you must supply keyColumnTypes at minimum; supplying only columnTypes is not enough to satisfy this guard.","commonSituations":"Standalone migrations assemblies with hand-authored UpdateData for unmapped tables. Removing an entity type from the model while leaving its UpdateData migration behind. Running migrations via a custom host that does not supply the model.","solutions":["Supply keyColumnTypes: (and columnTypes:) on the UpdateData call so EF can build type mappings without a model.","Map the table to an entity type (modelBuilder.Entity<T>().ToTable(\"...\")) and ensure the migration runs with that model attached.","Manage seed data through HasData so EF scaffolds UpdateData with the model.","Register the migrations assembly with a provider that supplies the runtime model."],"exampleFix":"// before (no model, no key types):\nmigrationBuilder.UpdateData(\n    table: \"Lookups\",\n    keyColumns: new[] { \"Code\" },\n    keyValues: new object[,] { { \"A\" } },\n    columns: new[] { \"Description\" },\n    values: new object[,] { { \"Alpha\" } });\n\n// after (supply key types when there is no model):\nmigrationBuilder.UpdateData(\n    table: \"Lookups\",\n    keyColumns: new[] { \"Code\" },\n    keyColumnTypes: new[] { \"nvarchar(16)\" },\n    keyValues: new object[,] { { \"A\" } },\n    columns: new[] { \"Description\" },\n    columnTypes: new[] { \"nvarchar(200)\" },\n    values: new object[,] { { \"Alpha\" } });","handlingStrategy":"validation","validationCode":"static bool UpdateDataHasTypeSource(string[]? keyColumnTypes, IModel? model)\n{\n    return keyColumnTypes != null || model != null;\n}\n\n// usage: if no model is attached, you MUST pass keyColumnTypes (columnTypes recommended too)\nif (!UpdateDataHasTypeSource(keyColumnTypes, targetModel))\n    throw new InvalidOperationException(\"UpdateData needs a model or explicit keyColumnTypes.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await dbContext.Database.MigrateAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not associated with a model\") && ex.Message.Contains(\"data modification\"))\n{\n    logger.LogError(ex, \"UpdateData on an unmapped table needs explicit keyColumnTypes (and columnTypes) or a model.\");\n    throw;\n}","preventionTips":["Map every seeded table to an entity type so the model provides key type mappings.","For model-less migrations, always pass keyColumnTypes (and columnTypes) for UpdateData.","Run migrations with the runtime model attached.","Drive seed data through HasData so it stays bound to the model."],"tags":["migrations","data-seeding","update-data","type-mapping","invalidoperation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}