Skip to content

Scaffolding fails when a column exists with a default constraint name and a value equal to the CLR default #36567

@vasquezjames

Description

@vasquezjames

Bug description

I'm using .NET 10.0.0-preview.7.25380.108 to use the command dotnet ef dbcontext scaffold to get the schema of some tables, but I'm getting the error: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerAnnotationCodeGenerator.GenerateFluentApiCalls(IProperty property, IDictionary`2 annotations)

The same command work fine with .NET 9.0.7

Your code

I'm usign the following command in power shell:

PS C:\Users\jvasquez\source\repos\cmdContabiliza4\cmdContabiliza4> dotnet ef dbcontext scaffold --force --no-pluralize --use-database-names "Server=SERVIDOR;Database=nts_tarjcred;User Id=sa;Password=xxxxxx;Persist Security Info=False;Trust Server Certificate=true" Microsoft.EntityFrameworkCore.SqlServer -o nts_tarjcred -t tc_maestro -t tc_maestro_saldos -t tc_tdiferidos -t tc_bines -t tc_comercios -t tc_tarjetas -t tc_ttdiferidos -t tc_empresa -t tc_ptipoplasticos -t tc_binafinidadsub -t tc_ptipoconfig -t tc_ttipoconfig -t tc_binafinidad -t tc_tciclofactura -t tc_tciclofacturactual -t tc_ttipotrxrazon -t tc_negociadores -t tc_transacciones -t tc_tprocesotipotrx --verbose

Stack traces

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerAnnotationCodeGenerator.GenerateFluentApiCalls(IProperty property, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.Design.IAnnotationCodeGenerator.GenerateFluentApiCallsInternal(IAnnotatable annotatable, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.Design.AnnotationCodeGenerator.GenerateFluentApiCalls(IAnnotatable annotatable, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.ScaffoldingModelExtensions.GenerateAnnotations(IAnnotatable annotatable, Dictionary`2 annotations, IAnnotationCodeGenerator annotationCodeGenerator, Boolean isHandledByDataAnnotations)
   at Microsoft.EntityFrameworkCore.ScaffoldingModelExtensions.GetFluentApiCalls(IProperty property, IAnnotationCodeGenerator annotationCodeGenerator)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.TransformText()
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.ProcessTemplate(ITextTransformation transformation)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.
PS C:\Users\jvasquez\source\repos\cmdContabiliza4\cmdContabiliza4>

Verbose output

Found primary key on table 'PK_tc_empresa' with name 'dbo.tc_empresa'.
Found primary key on table 'PK_tc_maestro' with name 'dbo.tc_maestro'.
Found index on table 'IX_tc_maestro' with name 'dbo.tc_maestro', is unique: False.
Found index on table 'IX_tc_maestro_01' with name 'dbo.tc_maestro', is unique: False.
Found index on table 'IX_tc_maestro_02' with name 'dbo.tc_maestro', is unique: False.
Found index on table 'IX_tc_maestro_03' with name 'dbo.tc_maestro', is unique: False.
Found index on table 'IX_tc_maestro_04' with name 'dbo.tc_maestro', is unique: False.
Found primary key on table 'PK_tc_maestro_saldos' with name 'dbo.tc_maestro_saldos'.
Found index on table 'IX_tc_maestro_saldos_02' with name 'dbo.tc_maestro_saldos', is unique: False.
Found index on table 'IX_tc_maestro_saldos_03' with name 'dbo.tc_maestro_saldos', is unique: False.
Found index on table 'IX_tc_maestro_saldos_04' with name 'dbo.tc_maestro_saldos', is unique: False.
Found index on table 'IX_tc_maestro_saldos_05' with name 'dbo.tc_maestro_saldos', is unique: False.
Found index on table 'tc_maestro_saldos_01' with name 'dbo.tc_maestro_saldos', is unique: False.
Found primary key on table 'PK_tc_negociadores' with name 'dbo.tc_negociadores'.
Found index on table 'IX_tc_negociadores' with name 'dbo.tc_negociadores', is unique: False.
Found index on table 'IX_tc_negociadores03' with name 'dbo.tc_negociadores', is unique: False.
Found primary key on table 'PK_tc_ptipoconfig' with name 'dbo.tc_ptipoconfig'.
Found primary key on table 'PK_tc_ptipoplasticos' with name 'dbo.tc_ptipoplasticos'.
Found primary key on table 'PK_tc_tarjetas' with name 'dbo.tc_tarjetas'.
Found index on table 'IX_tc_tarjetas_1' with name 'dbo.tc_tarjetas', is unique: False.
Found index on table 'IX_tc_tarjetas_2' with name 'dbo.tc_tarjetas', is unique: False.
Found index on table 'IX_tc_tarjetas_3' with name 'dbo.tc_tarjetas', is unique: False.
Found primary key on table 'PK_tc_tciclofactura' with name 'dbo.tc_tciclofactura'.
Found index on table 'tc_tciclofactura_01' with name 'dbo.tc_tciclofactura', is unique: False.
Found primary key on table 'PK_tc_tciclofacturactual' with name 'dbo.tc_tciclofacturactual'.
Found primary key on table 'PK_tc_tdiferidos' with name 'dbo.tc_tdiferidos'.
Found index on table 'ix1' with name 'dbo.tc_tdiferidos', is unique: False.
Found index on table 'ix2' with name 'dbo.tc_tdiferidos', is unique: False.
Found index on table 'ix3' with name 'dbo.tc_tdiferidos', is unique: False.
Found index on table 'ix4' with name 'dbo.tc_tdiferidos', is unique: False.
Found index on table 'ix5' with name 'dbo.tc_tdiferidos', is unique: False.
Found primary key on table 'PK_tc_tprocesotipotrx' with name 'dbo.tc_tprocesotipotrx'.
Found index on table 'IX_tc_tprocesotipotrx_01' with name 'dbo.tc_tprocesotipotrx', is unique: False.
Found primary key on table 'PK_tc_transacciones' with name 'dbo.tc_transacciones'.
Found index on table 'ix1' with name 'dbo.tc_transacciones', is unique: False.
Found index on table 'ix2' with name 'dbo.tc_transacciones', is unique: False.
Found index on table 'ix3' with name 'dbo.tc_transacciones', is unique: False.
Found index on table 'ix4' with name 'dbo.tc_transacciones', is unique: False.
Found index on table 'ix5' with name 'dbo.tc_transacciones', is unique: False.
Found index on table 'Ix6' with name 'dbo.tc_transacciones', is unique: False.
Found primary key on table 'PK_tc_ttdiferidos' with name 'dbo.tc_ttdiferidos'.
Found primary key on table 'PK_tc_ttipoconfig' with name 'dbo.tc_ttipoconfig'.
Found primary key on table 'PK_tc_ttipotrxrazon' with name 'dbo.tc_ttipotrxrazon'.
Found index on table 'IX_tc_ttipotrxrazon_01' with name 'dbo.tc_ttipotrxrazon', is unique: False.
Found foreign key on table 'FK_tc_binafinidad_tc_tciclofacturactual' with name 'dbo.tc_binafinidad', principal table 'dbo.tc_tciclofacturactual', delete action NO_ACTION.
Found foreign key on table 'FK_tc_binafinidadsub_tc_binafinidad' with name 'dbo.tc_binafinidadsub', principal table 'dbo.tc_binafinidad', delete action NO_ACTION.
Found foreign key on table 'FK_tc_binafinidadsub_tc_ptipoplasticos' with name 'dbo.tc_binafinidadsub', principal table 'dbo.tc_ptipoplasticos', delete action NO_ACTION.
Found foreign key on table 'FK_tc_bines_tc_binesfuente' with name 'dbo.tc_bines', principal table 'dbo.tc_bines', delete action NO_ACTION.
Found foreign key on table 'FK_tc_bines_tc_binesintercambio' with name 'dbo.tc_bines', principal table 'dbo.tc_bines', delete action NO_ACTION.
Found foreign key on table 'FK_tc_bines_tc_empresa' with name 'dbo.tc_bines', principal table 'dbo.tc_empresa', delete action NO_ACTION.
Found foreign key on table 'FK_tc_empresa_tc_empresaadq' with name 'dbo.tc_empresa', principal table 'dbo.tc_empresa', delete action NO_ACTION.
Found foreign key on table 'FK_tc_empresa_tc_ttipoconfig' with name 'dbo.tc_empresa', principal table 'dbo.tc_ttipoconfig', delete action NO_ACTION.
Found foreign key on table 'FK_tc_maestro_saldos_tc_maestro' with name 'dbo.tc_maestro_saldos', principal table 'dbo.tc_maestro', delete action NO_ACTION.
Found foreign key on table 'FK_tc_negociadores_tc_empresa' with name 'dbo.tc_negociadores', principal table 'dbo.tc_empresa', delete action NO_ACTION.
Found foreign key on table 'FK_tc_ptipoplasticos_tc_ptipoconfig1' with name 'dbo.tc_ptipoplasticos', principal table 'dbo.tc_ptipoconfig', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tarjetas_tc_binafinidadsub' with name 'dbo.tc_tarjetas', principal table 'dbo.tc_binafinidadsub', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tarjetas_tc_maestro' with name 'dbo.tc_tarjetas', principal table 'dbo.tc_maestro', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tciclofactura_tc_tciclofacturactual' with name 'dbo.tc_tciclofactura', principal table 'dbo.tc_tciclofacturactual', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tciclofacturactual_tc_empresa' with name 'dbo.tc_tciclofacturactual', principal table 'dbo.tc_empresa', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tdiferidos_tc_comercios' with name 'dbo.tc_tdiferidos', principal table 'dbo.tc_comercios', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tdiferidos_tc_maestro_saldos' with name 'dbo.tc_tdiferidos', principal table 'dbo.tc_maestro_saldos', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tdiferidos_tc_tarjetas' with name 'dbo.tc_tdiferidos', principal table 'dbo.tc_tarjetas', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tdiferidos_tc_ttdiferidos' with name 'dbo.tc_tdiferidos', principal table 'dbo.tc_ttdiferidos', delete action NO_ACTION.
Found foreign key on table 'FK_tc_tprocesotipotrx_tc_ttipotrxrazon1' with name 'dbo.tc_tprocesotipotrx', principal table 'dbo.tc_ttipotrxrazon', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_comercios' with name 'dbo.tc_transacciones', principal table 'dbo.tc_comercios', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_maestro_saldos' with name 'dbo.tc_transacciones', principal table 'dbo.tc_maestro_saldos', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_negociadores' with name 'dbo.tc_transacciones', principal table 'dbo.tc_negociadores', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_tarjetas' with name 'dbo.tc_transacciones', principal table 'dbo.tc_tarjetas', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_ttdiferidos' with name 'dbo.tc_transacciones', principal table 'dbo.tc_ttdiferidos', delete action NO_ACTION.
Found foreign key on table 'FK_tc_transacciones_tc_ttipotrxrazon' with name 'dbo.tc_transacciones', principal table 'dbo.tc_ttipotrxrazon', delete action NO_ACTION.
Found foreign key on table 'FK_tc_ttipotrxrazon_tc_empresa' with name 'dbo.tc_ttipotrxrazon', principal table 'dbo.tc_empresa', delete action NO_ACTION.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerAnnotationCodeGenerator.GenerateFluentApiCalls(IProperty property, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.Design.IAnnotationCodeGenerator.GenerateFluentApiCallsInternal(IAnnotatable annotatable, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.Design.AnnotationCodeGenerator.GenerateFluentApiCalls(IAnnotatable annotatable, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.ScaffoldingModelExtensions.GenerateAnnotations(IAnnotatable annotatable, Dictionary`2 annotations, IAnnotationCodeGenerator annotationCodeGenerator, Boolean isHandledByDataAnnotations)
   at Microsoft.EntityFrameworkCore.ScaffoldingModelExtensions.GetFluentApiCalls(IProperty property, IAnnotationCodeGenerator annotationCodeGenerator)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.TransformText()
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.ProcessTemplate(ITextTransformation transformation)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.
PS C:\Users\jvasquez\source\repos\cmdContabiliza4\cmdContabiliza4>

EF Core version

10.0.0-preview.7.25380.108

Database provider

No response

Target framework

.NET 10

Operating system

No response

IDE

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions