Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Migration Seeds Error when the Entity Id is a Guid #841


User avatar
0
motaj1982 created

Could you help me?

That error just happen in Entities with Guid as Id...

In PACKAGE MANAGE CONSOLE:

PM> Update-Database -Verbose
Using StartUp project 'FGV.SCEO.Web'.
Using NuGet project 'FGV.SCEO.EntityFramework'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'FGV_DO_SCEO' (DataSource: tcp:DC7049.FGV.BR, Provider: System.Data.SqlClient, Origin: Configuration).
No pending explicit migrations.
Running Seed method.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Abp.EntityFramework.AbpDbContext.CheckAndSetId(DbEntityEntry entry)
   at Abp.EntityFramework.AbpDbContext.ApplyAbpConcepts()
   at Abp.EntityFramework.AbpDbContext.SaveChanges()
   at FGV.SCEO.Migrations.Seed.PopulaClassificacoesContabeis.AddClassificacaoContabilIfNotExists(ClassificacaoContabil item) in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\PopulaClassificacoesContabeis.cs:line 56
   at FGV.SCEO.Migrations.Seed.PopulaClassificacoesContabeis.CreateClassificacoesContabeis() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\PopulaClassificacoesContabeis.cs:line 43
   at FGV.SCEO.Migrations.Seed.PopulaClassificacoesContabeis.Create() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\PopulaClassificacoesContabeis.cs:line 36
   at FGV.SCEO.Migrations.Seed.InitialDbBuilder.Create() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\InitialDbBuilder.cs:line 26
   at FGV.SCEO.Migrations.Configuration.Seed(SCEODbContext context) in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Configuration.cs:line 16
   at System.Data.Entity.Migrations.DbMigrationsConfiguration`1.OnSeed(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator.SeedDatabase()
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.

Final Error: Object reference not set to an instance of an object.


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you for informing us. Fixed it: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/917">https://github.com/aspnetboilerplate/as ... issues/917</a> will be released in v0.8.3.

    Current workaround:

    When you create your DbContext set it's GuidGenerator property to SequentialGuidGenerator.Instance before using it.

  • User Avatar
    0
    motaj1982 created

    Good morning!

    The error still happening...

    PM> Update-Database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    No pending explicit migrations.
    Running Seed method.
    System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
       at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
       at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
       at System.Guid.Parse(String input)
       at FGV.SCEO.Migrations.Seed.PopulaTiposInsumos.CreateTiposInsumos() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\PopulaTiposInsumos.cs:line 38
       at FGV.SCEO.Migrations.Seed.PopulaTiposInsumos.Create() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\PopulaTiposInsumos.cs:line 27
       at FGV.SCEO.Migrations.Seed.InitialDbBuilder.Create() in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Seed\InitialDbBuilder.cs:line 29
       at FGV.SCEO.Migrations.Configuration.Seed(SCEODbContext context) in C:\Users\joao.damota\Desktop\SCEO\FGV.SCEO.EntityFramework\Migrations\Configuration.cs:line 16
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1.OnSeed(DbContext context)
       at System.Data.Entity.Migrations.DbMigrator.SeedDatabase()
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
       at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
       at System.Data.Entity.Migrations.DbMigrator.&lt;&gt;c__DisplayClassc.&lt;Update&gt;b__b()
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.&lt;&gt;c__DisplayClass2.&lt;.ctor&gt;b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
    

    Erro: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

  • User Avatar
    0
    hikalkan created
    Support Team

    Maybe your guid is wrong. can you share PopulaTiposInsumos.cs

  • User Avatar
    0
    motaj1982 created

    Hi!

    Sorry, was my wrong... All working very well.

    Thank you very much!