Repository navigation
Closed
Copy link
Description
Old migration generated in EF Core 2.1.0 break in EF Core 8.0.5.
In the old migration (first in our project) there is a column defined as:
MyEntityType = table.Column<int>(nullable: false, defaultValue: "")
Which has been working until now when I upgraded to .NET8/EFCore8.
If I remove defaultValue: "" the migration works as expected.
Stacktrace:
[11:01:56] Applying 20180809120006_Initial...
Object reference not set to an instance of an object.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindCollectionMapping(RelationalTypeMappingInfo info, Type modelType, Type providerType, CoreTypeMapping elementMapping)
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.<>c.<FindMappingWithConversion>b__8_0(ValueTuple`4 k, RelationalTypeMappingSource self)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, Type providerClrType, ValueConverter customConverter)
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, IReadOnlyList`1 principals)
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(Type type, String storeTypeName, Boolean keyOrIndex, Nullable`1 unicode, Nullable`1 size, Nullable`1 rowVersion, Nullable`1 fixedLength, Nullable`1 precision, Nullable`1 scale)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.DefaultValue(Object defaultValue, String defaultValueSql, String columnType, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.ColumnDefinition(String schema, String table, String name, ColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
EF Core version: 8.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: (e.g. .NET 8.0)
Operating system: Windows 10
Reacted by Copilot
Activity
8 remaining items
kirylbokach commentedon Aug 18, 2025
I was having the same issue when trying to switch the discriminator column type from
varchar(50)tosmallintand forgetting to switch the property type from string to enum. Once switched the NRE goes awayGenerates NRE:
Works:
The diff is in the line before the last one ( -> )
Fix NullReferenceException for mistyped default values on non-string …