Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Npgsql.PostgresException (0x80004005): 42P07: relation "__EFMigrationsHistory" already exists #5901

Closed
1 task done
fffapch opened this issue Apr 4, 2024 · 5 comments
Milestone

Comments

@fffapch
Copy link

fffapch commented Apr 4, 2024

What is your BTCPay version?

BTCPAYSERVER: 1.12.3

How did you deploy BTCPay Server?

Docker

What happened?

An unhandled Npgsql.PostgresException exception occurred at startup BTCPAYSERVER.
It looks like EF tries to apply already applied migrations for tables where schema is different from public.
Only affects databases where public isn't the main schema.

How did you encounter this bug?

Faced with the error after updating BTCPAYSERVER from 1.11.7 to 1.12.3 version

Relevant log output

Unhandled exception. Npgsql.PostgresException (0x80004005): 42P07: relation "__EFMigrationsHistory" already exists	btcpayserver
	at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)	btcpayserver
	at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)	btcpayserver
	at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)	btcpayserver
	at BTCPayServer.Hosting.MigrationStartupTask.Migrate(CancellationToken cancellationToken) in /source/BTCPayServer/Hosting/MigrationStartupTask.cs:line 862	btcpayserver
	at BTCPayServer.Hosting.MigrationStartupTask.ExecuteAsync(CancellationToken cancellationToken) in /source/BTCPayServer/Hosting/MigrationStartupTask.cs:line 85	btcpayserver
	at Microsoft.AspNetCore.Hosting.WebHostExtensions.StartWithTasksAsync(IWebHost webHost, CancellationToken cancellationToken) in /source/BTCPayServer/Extensions/WebHostExtensions.cs:line 19	btcpayserver
	at BTCPayServer.Program.Main(String[] args) in /source/BTCPayServer/Program.cs:line 76	btcpayserver
	at BTCPayServer.Program.Main(String[] args) in /source/BTCPayServer/Program.cs:line 103	btcpayserver
	at BTCPayServer.Program.<Main>(String[] args)	btcpayserver
	Exception data:	btcpayserver
	Severity: ERROR	btcpayserver
	SqlState: 42P07	btcpayserver
	MessageText: relation "__EFMigrationsHistory" already exists	btcpayserver
	File: heap.c	btcpayserver
	Line: 1162	btcpayserver
	Routine: heap_create_with_catalog	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)	btcpayserver
	at BTCPayServer.Hosting.MigrationStartupTask.Migrate(CancellationToken cancellationToken) in /source/BTCPayServer/Hosting/MigrationStartupTask.cs:line 862	btcpayserver
	at BTCPayServer.Hosting.MigrationStartupTask.ExecuteAsync(CancellationToken cancellationToken) in /source/BTCPayServer/Hosting/MigrationStartupTask.cs:line 85	btcpayserver
	Exception data:	btcpayserver
	Severity: ERROR	btcpayserver
	SqlState: 42P07	btcpayserver
	MessageText: relation "__EFMigrationsHistory" already exists	btcpayserver
	File: heap.c	btcpayserver
	Line: 1162	btcpayserver
	Routine: heap_create_with_catalog	btcpayserver
	BTCPayServer.Hosting.MigrationStartupTask: Error on the MigrationStartupTask	btcpayserver
	Npgsql.PostgresException (0x80004005): 42P07: relation "__EFMigrationsHistory" already exists	btcpayserver
	at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)	btcpayserver
	at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)	btcpayserver
	at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)	btcpayserver
	at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)	btcpayserver
	at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)	btcpayserver
	2024-01-24T07:59:23Z New outbound-full-relay v1 peer connected: version: 70016, blocks=2575515, peer=4	bitcoind

What browser do you use?

No response

Additional information

No response

Are you sure this is a bug report?

  • I confirm this is a bug report
@NicolasDorier
Copy link
Member

You say you deployed using our docker deployment. But our docker deployment doesn't allow changing schema. How did you end up here?

@fffapch
Copy link
Author

fffapch commented Apr 5, 2024

In our project, we build a Docker file with a config where we define Search Path in PostgreSQL connectionString, e.g Host=;Port=;Database=;Search Path=boundedcontext;
Could you look at the next workaround with searchPaths? I believe it can solve this issue.

@NicolasDorier
Copy link
Member

thank you, will take a look! We will fix that for next minor

@NicolasDorier NicolasDorier added this to the 1.13.x milestone Apr 6, 2024
@NicolasDorier
Copy link
Member

Will release today

@NicolasDorier
Copy link
Member

NicolasDorier commented Apr 16, 2024

released 1.13.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants