Question:
I have an MVC application in DDD that uses SQLServer.
I'm looking to take the database to PostGresSQL, but there is an FK duplication error.
For example, in the default SqlServer it would be generated:
FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegaLegalId
FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegalId
But in PostGresSQL when generating the FK it tends to do:
FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLega -- ambas iguais
Is it possible to apply another rule when generating FK automatically?
Has anyone done this?
Answer:
According to the documentation , an identifier can only be up to 63 characters long.
Need to use foreign key with shorter name. Try using an annottation in its 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");
}