Open Closed

Migration Issue #6598


User avatar
0
dipak.z created
  • ABP Framework version: v8.02
  • UI Type: MVC
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I am migrating custom modules code from abp 5.2.1 to abp 8.0.2 when i migrate then

builder.Entity<TempLayer>(b =>
{
    b.ToTable(SGLLayerManagementConsts.DbTablePrefix + nameof(TempLayer));
    b.ConfigureByConvention();
    b.HasKey(e => e.Id);
    b.Property(e => e.Id).AutoGenerateGuidNpgSql();

    b.HasKey(e => e.TempLayerId);
    b.Property(e => e.TempLayerId).AutoGenerateGuidNpgSql();

    b.Property(e => e.LayerName)
        .IsRequired();

    b.Property(e => e.BoundX1)
        .IsRequired();

    b.Property(e => e.BoundX2)
        .IsRequired();

    b.Property(e => e.BoundY1)
        .IsRequired();

    b.Property(e => e.BoundY2)
        .IsRequired();

    b.Property(e => e.IsSync)
        .IsRequired()
        .HasDefaultValue(true);

    b.Property(e => e.IsQueryable)
        .IsRequired()
        .HasDefaultValue(true);

    b.HasMany(e => e.LayerFields)
        .WithOne(e => e.Layer)
        .HasForeignKey(e => e.LayerId);
    b.ApplyObjectExtensionMappings();
});

builder.Entity<TempLayerField>(b =>
{
    b.ToTable(SGLLayerManagementConsts.DbTablePrefix + nameof(TempLayerField));
    b.ConfigureByConvention();
    b.HasKey(e => e.Id);
    b.Property(e => e.Id).AutoGenerateGuidNpgSql();

    b.Property(e => e.LayerFieldName)
        .IsRequired();

    b.Property(e => e.TableName)
        .IsRequired();

    b.Property(e => e.AreSame)
        .IsRequired()
        .HasDefaultValue(false);

    b.HasOne(e => e.Layer)
      .WithMany(e => e.LayerFields)
      .HasForeignKey(e => e.LayerId);
});

TempLayer class is AuditedAggregateRoot<Guid> & IMultiTenant when insert data in this using efcore then throw below error

23502: null value in column "ExtraProperties" violates not-null constraint DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    HI,

    Is this working for you?

    builder.Entity<TempLayer>(b =>
    {
        b.ToTable(SGLLayerManagementConsts.DbTablePrefix + nameof(TempLayer));
        b.ConfigureByConvention();
        b.HasKey(e => e.Id);
        b.Property(e => e.Id).AutoGenerateGuidNpgSql();
    
        b.HasKey(e => e.TempLayerId);
        b.Property(e => e.TempLayerId).AutoGenerateGuidNpgSql();
    
        b.Property(e => e.LayerName)
            .IsRequired();
    
        b.Property(e => e.BoundX1)
            .IsRequired();
    
        b.Property(e => e.BoundX2)
            .IsRequired();
    
        b.Property(e => e.BoundY1)
            .IsRequired();
    
        b.Property(e => e.BoundY2)
            .IsRequired();
    
        b.Property(e => e.IsSync)
            .IsRequired()
            .HasDefaultValue(true);
    
        b.Property(e => e.IsQueryable)
            .IsRequired()
            .HasDefaultValue(true);
    
        b.HasMany(e => e.LayerFields)
            .WithOne(e => e.Layer)
            .HasForeignKey(e => e.LayerId);
        b.ApplyObjectExtensionMappings();
        
    
       b.Property(e => e.ExtraProperties).IsRequired(false);  add this line
    });
    

    Add&Apply new migration.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    dipak.z created

    HI,

    Is this working for you?

    builder.Entity<TempLayer>(b => 
    { 
        b.ToTable(SGLLayerManagementConsts.DbTablePrefix + nameof(TempLayer)); 
        b.ConfigureByConvention(); 
        b.HasKey(e => e.Id); 
        b.Property(e => e.Id).AutoGenerateGuidNpgSql(); 
     
        b.HasKey(e => e.TempLayerId); 
        b.Property(e => e.TempLayerId).AutoGenerateGuidNpgSql(); 
     
        b.Property(e => e.LayerName) 
            .IsRequired(); 
     
        b.Property(e => e.BoundX1) 
            .IsRequired(); 
     
        b.Property(e => e.BoundX2) 
            .IsRequired(); 
     
        b.Property(e => e.BoundY1) 
            .IsRequired(); 
     
        b.Property(e => e.BoundY2) 
            .IsRequired(); 
     
        b.Property(e => e.IsSync) 
            .IsRequired() 
            .HasDefaultValue(true); 
     
        b.Property(e => e.IsQueryable) 
            .IsRequired() 
            .HasDefaultValue(true); 
     
        b.HasMany(e => e.LayerFields) 
            .WithOne(e => e.Layer) 
            .HasForeignKey(e => e.LayerId); 
        b.ApplyObjectExtensionMappings(); 
         
     
       b.Property(e => e.ExtraProperties).IsRequired(false);  add this line 
    }); 
    

    Add&Apply new migration.

    I have to add this line for all entities & in all modules? its not like that in abp 5.2.1

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    I have to add this line for all entities & in all modules? its not like that in abp 5.2.1

    No, Usually ExtraProperties have a default value, which should not be null. I'm guessing this might have something to do with your code, but I don't know the details

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    dipak.z created

    Hi,

    I have to add this line for all entities & in all modules? its not like that in abp 5.2.1

    No, Usually ExtraProperties have a default value, which should not be null. I'm guessing this might have something to do with your code, but I don't know the details

    i am using this for bulk insertdata and i am not passed extraproperties in this

    public async Task BulkInsert<TEntity>(IEnumerable<TEntity> entities, params string[] properties)
    {
        var dbcontext = await GetDbContextAsync().ConfigureAwait(false);
        using var connection = new NpgsqlConnection(dbcontext.Database.GetDbConnection().ConnectionString);
    
        var mapping = dbcontext.Model.FindEntityType(typeof(TEntity));
        const string schema = "public";// mapping.GetSchema();
        var tableName = mapping.GetTableName();
        string query = $"Insert into \"{schema}\".\"{tableName}\" ({properties.Select(p => "\"" + p + "\"").ToCSV()}) values ({properties.Select(p => "@" + p).ToCSV()})";
        _ = await connection.ExecuteAsync(query, entities).ConfigureAwait(false);
    }
    

    and its works fine in abp 5.2.1

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    and its works fine in abp 5.2.1

    Starting from 8.0, ABP supports Nullable reference types: https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references That's why it doesn't work.

    You may consider manually assigning values ​​to ExtraProperties, or setting it to a nullable field

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❀️ on ABP v10.8.0-preview. Updated on September 09, 2026, 11:56
1
ABP Assistant
πŸ” You need to be logged in to use the chatbot. Please log in first.