Skip to content

Name claims take a table without a schema and a table in public for two schemas, and the collision fails at apply #100

Closed

Description

@CaffeinatedCoder

Found by the pre-preview sweep of main @ 948496a (lens: base operations; a lead of the new-check lens and of GPT's read); reproduced on PostgreSQL 18.

What happens

The model sets no default schema. An exclusion constraint is on role_grants (no schema), and an EF Core index of the same name is on ToTable("bookings", "public"). No SK1001 is raised, and the migration fails at apply:

CREATE INDEX ex_role_grant_active_period ON public.bookings ("RoomId");
ALTER TABLE role_grants ADD CONSTRAINT ex_role_grant_active_period EXCLUDE USING gist (…);
-- 42P07: relation "ex_role_grant_active_period" already exists

Why

The claims are Relation(null, name) and Relation("public", name), and NameClaims compares the schemas as text (NameClaims.cs:108-124). The relational model carries a model's default schema where one is set; where none is, the schema is null and the server puts the table where search_path says, which is public on a stock database. NpgsqlSchemaDialect.Claims does not say that.

Scenario

public sealed class NullSchemaAndPublic : ITestModel
{
    public static void Build(ModelBuilder b)
    {
        b.Entity<RoleGrant>().ToTable("role_grants").DeclarePostgres(_ => [Models.ActivePeriod]);
        b.Entity<Booking>().ToTable("bookings", "public").HasIndex(x => x.RoomId).HasDatabaseName(Models.Name);
    }
}

[TestMethod]
public void A_table_without_a_schema_and_one_in_public_share_a_namespace()
{
    using var database = new LiveDatabase();
    Assert.ThrowsExactly<SchemaValidationException>(database.Create<NullSchemaAndPublic>);   // PostgresException 42P07
}

Change

The dialect names the schema a table without one lands in (public for PostgreSQL, dbo for SQL Server with #29), and claims are compared under it. A search_path that says otherwise is a database the model does not describe.

Test

A row in NameClaimTests offline, its row in NameClaimLiveTests, as for every other row of the namespace table.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    bug
    package/core
    package/postgresql
    severity/medium
    area/migrations
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/migrationsbugpackage/corepackage/postgresqlseverity/medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions