efcore.pg: Can't scaffold pre-10 PostgreSQL with v3.0.0-preview8 because of missing pg_sequence schema table

I have a problem with database reverse engineering using Postgresql 9.5 and Npgsql 3.0.0-preview8 on dotnercore 3.0.100-preview8-013656.

The scaffolding fails with the following error :

the relation « pg_sequence » does not exist

If I’m not mistaken, newer versions of Npgsql use Postgresql 10/11 compatibility by default. How can I generate my dbContext from the database using dotnet command line with PG9.5 compatibility ?

I already set services.AddDbContextPool<myContext>(options => options.UseNpgsql(Configuration["ConnectionStrings:DefaultConnection"], o => o.SetPostgresVersion(9,5))); in my Startup class.

Is there a command line argument to ensure compatibility ?

Here is the command line I use :

dotnet ef dbcontext -p Target.Project.Name -s Startup.Project.Name scaffold `
	"Host=hostname;Port=1525;Database=dbname;Username=user;Password=pass" `
	Npgsql.EntityFrameworkCore.PostgreSQL `
	--context-dir . `
	--schema data `
	--table othershema.table `
	-o Entities `
	-f `
	-d

It worked without issues when I was using dotnetcore 2.2, but I wanted to update my project to be able to test the scaffolding of views.

Here is the full stack trace from dotnet command

Npgsql.PostgresException (0x80004005): 42P01: la relation « pg_sequence » n'existe pas
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal.NpgsqlDatabaseModelFactory.GetColumns(NpgsqlConnection connection, IReadOnlyList`1 tables, String tableFilter, HashSet`1 enums, IDiagnosticsLogger`1 logger)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal.NpgsqlDatabaseModelFactory.GetTables(NpgsqlConnection connection, Func`3 tableFilter, HashSet`1 enums, IDiagnosticsLogger`1 logger)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal.NpgsqlDatabaseModelFactory.Create(DbConnection dbConnection, DatabaseModelFactoryOptions options)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal.NpgsqlDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  Exception data:
    Severity: ERREUR
    SqlState: 42P01
    MessageText: la relation « pg_sequence » n'existe pas
    Position: 1456
    File: parse_relation.c
    Line: 1159
    Routine: parserOpenTable

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Unfortunately there’s not much I can do without a schema… Can you try copying only that table and schema to a new database (you can drop any foreign key constraints etc.) and see if the problem repros there? If it does, you can send that to me for investigation. If you’d prefer to keep this private, you can send it to the email listed on my github profile.

In any case, if you manage to repro it, can you please open a new issue with the necessary details? Your problem isn’t the same as this issue.

Thanks @roji It worked for postgresSQL 13.2 …Thanks for your quick support

@rezabayesteh can you please be most specific? This problem only occurred on version older than PostgreSQL 10, so if you’re seeing something on that version that’s probably a completely different issue. Ideally, please open a new issue with a minimal database schema that fails to scaffold.