locked
Trying to do migration in my asp .net Entity Framework core web application but getting following error. RRS feed

  • Question

  • User2022958837 posted

    PM> add-migration yashnew
    Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
    User profile is available. Using 'C:\Users\Yash Gandhi\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
    Microsoft.EntityFrameworkCore.Model[10605]
    There are multiple relationships between 'Applicant' and 'Career' without configured foreign key properties causing EF to create shadow properties on 'Applicant' with names dependent on the discovery order.
    Microsoft.EntityFrameworkCore.Infrastructure[10403]
    Entity Framework Core 2.2.3-servicing-35854 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Microsoft.EntityFrameworkCore.Update.Internal.SharedTableEntryMap`1.CreateSharedTableEntryMapFactory(IReadOnlyList`1 entityTypes, IStateManager stateManager, String tableName, String schema)
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffData(TableMapping source, TableMapping target, DiffContext diffContext)
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<Diff>d__35.MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<DiffCollection>d__73`1.MoveNext()
    at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
    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)
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
    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.
    PM>

    Trying to find <g class="gr_ gr_46 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" id="46" data-gr-id="46">solution</g> but not getting.

    Wednesday, April 17, 2019 4:56 AM

All replies

  • User1120430333 posted

    Object reference not set to an instance of an object

    That's an un-exposable situation as far as to what is causing the error message, becuase you have no control of the migration code that EF is using internally,  what it  is doing  and what has caused the error. You can't see anything other than some error message that  has been spat-out. 

    Myself, I avoid migrations. 

    Wednesday, April 17, 2019 6:15 AM
  • User1724605321 posted

    Hi yashgandhideveloper ,

    Please show your Entities , if you use fluent api to config the relationship , please also provide that .

    Best Regards,

    Nan Yu

    Thursday, April 18, 2019 1:58 AM
  • User2022958837 posted

    Got solution for any migration problem. perform the following steps.

    1) Delete Migration folder.

    2) open Nuget package manager console

    3)PM>Add-Migration init

    a new migration folder will get created

    4)PM>Add-Migration <Migration_Name>

    5) PM>Update Database

    your database will get updated with new changes.

    your program is ok now

    Wednesday, April 24, 2019 2:44 AM