Migration Conventions

Asked

Viewed 32 times

3

I have an MVC DDD application that uses Sqlserver.

I’m trying to get the database to Postgressql, but there is a FK duplicity error.

For example, the default Sqlserver would be generated:

FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegaLegalId
FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLegalId

But in Postgressql when generating FK he tends to do:

FK_dbo.Adicao_dbo.OrgaoEmissorAtoLegal_ExTarifOrgEmissorAtoLega -- ambas iguais

It is possible to apply another rule in FK generation automatically?
Someone’s already done it?

  • Which version of postgresql you are using?

  • I’ve been reading the documentation and an identifier can be up to 63 characters long. Check if there is no prefix inclusion in fk’s name in the generation. (https://til.hashrocket.com/posts/8f87c65a0a-postgresqls-max-identifier-length-is-63-bytes)

  • the version is 9.6.10.

  • Exactly the indicator goes up to 63 characters, but there is a way to say this for Migration so that when generating the FK apply this new rule?

1 answer

0

According to the documentation, an identifier may only be up to 63 characters long.

Need to use foreign key with smaller name. Try to use an annottation in the generation of it to decrease the name.

From what I’ve seen you use Fluent. You can use an alternative modeling for cases 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");
 }
  • Regarding applying short names is quiet, but I don’t want to assign names to each object, I need Migration to control this and apply the new rule, if not when I rename a field that generates a drop to FK, I have to keep managing it with a group of devs gets problematic

  • In my view you have an architecture error prior to the current problem. The names have already been created too long at the beginning of life of the application. A change in the load of the application would not be no worm 7 heads before the mistakes of the past. But it is an idea. I hope it helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.