Skip to content

Upgrade to .NET 10 - migrations drop and recreate primary keys for same name PKs on different schemas #3704

@ocoster-sermo

Description

@ocoster-sermo

I have multiple schemas with tables that share the same primary key name, which PostgreSQL allows.

For example:

  • table a on schema b will get a PK name of PK_a
  • table a on schema c will get the same PK name

This works fine up to .NET 8/9.

After upgrading to EF Core 10, migrations try to drop and recreate these PKs, breaking foreign key constraints.

Instead of enforcing uniqueness across all tables, it would be great if SharedTableConvention also considered the schema.

As @roji said in this comment on issue 3639:

PK constraint names are scoped to their schema - it's OK to have the same constraint name for two tables, just as long as they're not within the schema.

Attached minimal repro (code started with .NET 8 and upgraded to 10 - showing the bad migration):

repro.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions