efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
234 stars 27 forks source link

NullReferenceException when deleting optional fields #154

Open Mrjuanblack opened 1 year ago

Mrjuanblack commented 1 year ago

Describe the bug Hello, I'm getting a NullReferenceException each time I try to create a migration where I delete any optional field from any defined entity.

To Reproduce

  1. Have the following entity:

    [<CLIMutable>]
    type Dossier = {
    [<Key>]
    [<DatabaseGenerated(DatabaseGeneratedOption.Identity)>]
    Id : int
    TypeOfDossier : TypeOfDossier.TypeOfDossier
    InspectionLocation : InspectionLocation.InspectionLocation
    ...
    // Address
    Street : string
    Number : string
    Bus : string option
    PostalCode : string
    City : string
    ...
    OrderConfirmation : string option
    AssigmentConfirmation : string option
    Certificate : string option
    Lab : string option
    
    OrderConfirmationPhysicallySigned : string option
    AssignmentConfirmationPhysicallySigned : string option
    
    ManualInvoice: bool
    }  
  2. Remove OrderConfirmationPhysicallySigned and/or AssignmentConfirmationPhysicallySigned (or any other optional field, I've tried with other optional text fields in other entities too)
  3. Create a new migration
  4. Get the following error:

    System.NullReferenceException: Object reference not set to an instance of an object.
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(IColumn target, DiffContext diffContext, Boolean inline)+MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
    
    at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
    
    at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target)
    at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
    at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>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.

Expected behavior A new migration without the deleted fields

Additional context We are using PostgreSQL as our db