You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A table moved back to the default schema stays where it was on Npgsql, and a statement written after the move fails with 42P01 #105
area/migrationsThe differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiringbugSomething isn't workingpackage/postgresqlAffects CodoMetis.EFCore.SchemaKit.PostgreSQLseverity/mediumInconsistency or failure in a narrow scenario
Found by the pre-preview sweep of main @ 948496a (lens: base operations); reproduced on PostgreSQL 16 and 18.
What happens
A table moves from a schema of its own back to the default one: ToTable("role_grants", "grants") becomes ToTable("role_grants"), or HasDefaultSchema("app") is removed. This is also the Down of every move into a schema.
With no SchemaKit declaration at all, the migration applies and the table stays in grants. Npgsql 11.0.0-rc.3 writes ALTER TABLE … SET SCHEMA only when RenameTableOperation.NewSchema is not null (decompiled NpgsqlMigrationsSqlGenerator.Generate(RenameTableOperation)).
With an exclusion constraint that stays as it is, the constraint stays with the table, in grants. EnsureCreated() for the same model puts both in public.
With one that is rebuilt in the same migration, the create names the table without a schema and fails: 42P01: relation "role_grants" does not exist.
The planner records TableMoved(grants → null) and takes the table for moved.
Whose it is
Npgsql's. SchemaKit writes nothing wrong for the model it is given, and where it writes nothing the database differs from the model without any package noticing. It is tracked here because a consumer meets it through SchemaKit's statement, and because the move forward is a case the live tests hold (Moving_the_table_to_another_schema) while the way back is not.
Change
A report upstream (npgsql/efcore.pg), by the maintainer.
To decide: whether the planner refuses a TableMoved to a null schema on Npgsql while the provider does not write it. It would refuse a migration that today applies and leaves the table behind.
Test
AssertMigratesTo<Models.SchedulingMoved, Models.Scheduling> in PgExclusionLiveTests, which fails today on the schema in the catalog, kept as the measure of the upstream fix.
2026-11-25: still so on the released Npgsql.EntityFrameworkCore.PostgreSQL 11.0.0, and SchemaKit refuses it now (#198, decided with #116). With an object on the table the migration is refused where it is scaffolded, and the refusal says to name the schema, ToTable("x", "public"), which Npgsql writes. NpgsqlOperationEffectTests.A_move_back_to_the_default_schema_is_not_written_and_the_dialect_says_so asserts that the generator writes nothing, and fails when it does: the rule and the refusal then go.
A reproduction for the report upstream (npgsql/efcore.pg), with no SchemaKit in it:
usingMicrosoft.EntityFrameworkCore;usingMicrosoft.EntityFrameworkCore.Infrastructure;usingMicrosoft.EntityFrameworkCore.Migrations;usingMicrosoft.EntityFrameworkCore.Migrations.Operations;usingvarcontext=newDb();vargenerator=context.GetService<IMigrationsSqlGenerator>();stringSql(string?from,string?to)=>string.Join("\n",generator.Generate([newRenameTableOperation{Name="role_grants",Schema=from,NewName="role_grants",NewSchema=to}]).Select(command =>command.CommandText));Console.WriteLine($"into a schema: [{Sql(null,"grants")}]");// ALTER TABLE role_grants SET SCHEMA grants;Console.WriteLine($"back: [{Sql("grants",null)}]");// nothingsealedclassDb:DbContext{protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptions)=>options.UseNpgsql("Host=localhost");}
What a consumer sees: ToTable("role_grants", "grants") becomes ToTable("role_grants"), migrations add scaffolds RenameTable(name: "role_grants", schema: "grants", newName: "role_grants"), the migration applies, and the table is still in grants. It is also the Down of every move into a schema. Expected: ALTER TABLE grants.role_grants SET SCHEMA public;, or the schema the model's default is.
area/migrationsThe differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiringbugSomething isn't workingpackage/postgresqlAffects CodoMetis.EFCore.SchemaKit.PostgreSQLseverity/mediumInconsistency or failure in a narrow scenario
Activity
CaffeinatedCoder commentedon Nov 25, 2026
2026-11-25: still so on the released
Npgsql.EntityFrameworkCore.PostgreSQL11.0.0, and SchemaKit refuses it now (#198, decided with #116). With an object on the table the migration is refused where it is scaffolded, and the refusal says to name the schema,ToTable("x", "public"), which Npgsql writes.NpgsqlOperationEffectTests.A_move_back_to_the_default_schema_is_not_written_and_the_dialect_says_soasserts that the generator writes nothing, and fails when it does: the rule and the refusal then go.A reproduction for the report upstream (npgsql/efcore.pg), with no SchemaKit in it:
What a consumer sees:
ToTable("role_grants", "grants")becomesToTable("role_grants"),migrations addscaffoldsRenameTable(name: "role_grants", schema: "grants", newName: "role_grants"), the migration applies, and the table is still ingrants. It is also theDownof every move into a schema. Expected:ALTER TABLE grants.role_grants SET SCHEMA public;, or the schema the model's default is.