{"record":{"id":"cb1878f5861b7a6a","repo":"dotnet/efcore","slug":"the-data-deletion-operation-on-table-is-not-as","errorCode":null,"errorMessage":"The data deletion 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 deletion 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":985,"sourceCode":"        if (operation.KeyColumns.Length != operation.KeyValues.GetLength(1))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DeleteDataOperationValuesCountMismatch(\n                    operation.KeyValues.GetLength(1), operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.KeyColumnTypes != null\n            && operation.KeyColumns.Length != operation.KeyColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DeleteDataOperationTypesCountMismatch(\n                    operation.KeyColumnTypes.Length, operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.KeyColumnTypes == null\n            && model == null)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DeleteDataOperationNoModel(\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\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.Deleted;\n\n            for (var j = 0; j < operation.KeyColumns.Length; j++)\n            {\n                var name = operation.KeyColumns[j];\n                var value = operation.KeyValues[i, j];","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L967-L1003","documentation":"Thrown for a DeleteData operation when neither KeyColumnTypes nor a model is available. Without one of them EF cannot determine the store type for each key parameter, so it refuses to emit SQL. The migration must either be tied to a model or declare column types explicitly.","triggerScenarios":"migrationBuilder.DeleteData(...) with no keyColumnTypes, executed in a context where the migration has no target model (model == null). Common with standalone MigrationBuilder instances used outside the Migrator, or with providers that pass null model.","commonSituations":"Calling migrationBuilder.BuildTargetModel-less pipelines. Design-time scaffolding that runs operations without an IModel. Removing the [DbContext] target from a migration. Using a migrations-only assembly that has no DbContext.","solutions":["Pass keyColumnTypes for every key column so EF can resolve type mappings without a model.","Ensure the migration is produced via Add-Migration so it carries a BuildTargetModel method that supplies the IModel.","If invoking MigrationBuilder manually, supply the model through the Migrator / migrations infrastructure rather than calling Generate directly."],"exampleFix":"// before\nmigrationBuilder.DeleteData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 } });\n\n// after\nmigrationBuilder.DeleteData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyColumnTypes: new[] { \"int\" },\n    keyValues: new object[,] { { 10 } });","handlingStrategy":"validation","validationCode":"void EnsureDeleteDataResolvable(string[]? keyColumnTypes, IModel? model, string table)\n{\n    if (keyColumnTypes is null && model is null)\n        throw new InvalidOperationException($\"{table}: DeleteData needs either keyColumnTypes or a model.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always generate migrations via dotnet ef migrations add so BuildTargetModel is emitted.","When using MigrationBuilder standalone, pass keyColumnTypes for every key column.","Avoid hand-editing migrations to remove BuildTargetModel."],"tags":["ef-core","migrations","deletedata","model-binding"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}