Scaffold-DbContext not adding schema parameter to modelBuilder.HasSequence #15513
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
DB context scaffold does not generate
modelBuilder.HasSequence
method call withschema
parameter in DbContext's OnModelCreating method.For me, it caused a problem in table creation when initializing a PostgreSQL database with a DB context generated by DB context scaffold.
Because my table has a column of
serial
type, the table depends on a sequence in the same schema. However, the generated DB context does not specify the schema for the sequence because of the scaffold's behavior above, and thus the sequence does not exist in the same schema when the table is created and the table creation fails.The followings are SQL that created the original table, and the error that I got from
dotnet ef dbcontext scaffold
.I confirmed that the table creation succeeds once I add the schema parameter to the
modelBuilder.HasSequence
method call as shown below. Therefore, the schema parameter should be appended in the generated code as long as database provider provides the sequence's schema.I also confirmed it in the PostgreSQL database provider that
NpgsqlDatabaseModelFactory
does set sequence schema before adding sequence info toDatabaseModel
, so that something is wrong in EF Core.Steps to reproduce
I uploaded test code to reproduce the issue to one of my repositories.
Further technical details
.NET Core SDK 2.2.105
EF Core version: 2.2.4
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL 2.2.0
Operating system: macOS
The text was updated successfully, but these errors were encountered: