Migration Conventions

3

I have an MVC application in DDD that uses SQLServer.

I'm looking to take the database to PostGresSQL, but an FK duplicity error occurs.

For example, in the SqlServer pattern would be generated:

FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegaLegalId
FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegalId

But in PostGresSQL when generating FK it tends to do:

FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLega -- ambas iguais

Is it possible to apply another rule in FK generation automatically?
Has anyone done this yet?

    
asked by anonymous 05.10.2018 / 21:19

1 answer

0

According to documentation , an identifier can only have up to 63 characters.

You need to use a foreign key with a smaller name. Try to use an annottation in the same generation to shorten the name.

From what I've seen you use Fluent. You can use an alternative modeling for the cases of using postgresql instead of sql server.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
        modelBuilder.Entity<Post>()
            .HasOne(p => p.Blog)
            .WithMany(b => b.Posts)
            .HasForeignKey(p => p.BlogId)
            .HasConstraintName("ForeignKey_Post_Blog");
 }
    
05.10.2018 / 21:55