dotnet/efcore · error · InvalidOperationException
There is no entity type mapped to the table
Error message
There is no entity type mapped to the table '{table}' which is used in a data operation. Either add the corresponding entity type to the model, or specify the column types in the data operation. What it means
Thrown by GetPropertyMappings when a data operation references a table that does not exist in the relational model. EF needs the table to look up column metadata for type resolution.
Solutions
- Correct the table name (and schema) in the data operation to match the entity's ToTable mapping.
- Move the DeleteData/UpdateData call after the CreateTable/AddColumn that defines the table in this migration.
- Supply keyColumnTypes/columnTypes explicitly so GetPropertyMappings is bypassed.
- Re-scaffold the migration to capture the correct table reference.
Example fix
// before
migrationBuilder.DeleteData(
table: "Usrs", // typo
keyColumns: new[] { "Id" },
keyValues: new object[,] { { 10 } });
// after
migrationBuilder.DeleteData(
table: "Users",
keyColumns: new[] { "Id" },
keyValues: new object[,] { { 10 } }); Defensive patterns
Strategy: validation
Validate before calling
static void VerifyTableExists(IModel model, string table, string? schema)
{
var t = model.GetRelationalModel().FindTable(table, schema ?? model.GetDefaultSchema());
if (t is null)
throw new InvalidOperationException($"Table {schema}.{table} not present in the relational model.");
} Prevention
- Reference table names exactly as mapped by ToTable.
- Order migration operations so CreateTable precedes DeleteData/UpdateData.
- Pass explicit column types to bypass model table lookup when in doubt.
When it happens
Trigger: DeleteData/UpdateData referencing a table name that model.GetRelationalModel().FindTable(...) cannot resolve. Only fires when explicit types are NOT supplied, so the model must be consulted.
Common situations: Typos in table name. Data operation placed in a migration before the CreateTable that introduces the table. Split migrations where the table lives in a different migration. Schema mismatch (custom schema vs default).
Related errors
- There is no property mapped to the column
- The data deletion operation on
- The data modification operation on
- A seed entity for entity type
- values were provided in CreateIndexOperations.IsDescending…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/bb81bde4cc6901cb.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs:1170
}
yield return modificationCommand;
}
}
private static string FormatTable(string table, string? schema)
=> schema == null ? table : schema + "." + table;
private static IColumnMapping[] GetPropertyMappings(
string[] names,
string tableName,
string? schema,
IModel? model)
{
var table = model?.GetRelationalModel().FindTable(tableName, schema ?? model.GetDefaultSchema());
if (table == null)
{
throw new InvalidOperationException(
RelationalStrings.DataOperationNoTable(
FormatTable(tableName, schema)));
}
var properties = new IColumnMapping[names.Length];
for (var i = 0; i < names.Length; i++)
{
var name = names[i];
var column = table.FindColumn(name);
if (column == null)
{
throw new InvalidOperationException(
RelationalStrings.DataOperationNoProperty(
FormatTable(tableName, schema), name));
}
properties[i] = column.PropertyMappings.First();
}View on GitHub (pinned to 3a2006ef56)