The operation has timed out on EF Core migration to PostgreSQL

c# docker entity-framework-core identityserver4 postgresql


I am new to PostgreSQL and I would like to use it with Identity Server 4. I am using next NuGet packages: IdentityServer4, IdentityServer4.EntityFramework and Npgsql.EntityFrameworkCore.PostgreSQL

I am trying to make migration for Identity Server tables on PostgreSQL. I am modifying ConfigureServices in Startup.cs with:

string connectionString = "Server=; Port=5432; Database=postgres; User Id=postgres;Password=mysecretpassword";
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

        .AddConfigurationStore(options =>
            options.ConfigureDbContext = builder =>
                builder.UseNpgsql(connectionString, action=>

When I run Add-Migration command, I can see that VS prepares all migration information for me (I can see all the tables that I need), but when I run Update-Database command I get some weird error:

Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 2.1.4-rtm-31024 initialized 'ConfigurationDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=MangEx.Users System.TimeoutException: The operation has timed out. at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout) in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 703 at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 555 at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 414 at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<g__OpenLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 270 --- End of stack trace from previous location where exception was thrown --- at Npgsql.NpgsqlConnection.Open() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 153 at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists() in C:\projects\EFCore.PG\src\EFCore.PG\Storage\Internal\NpgsqlDatabaseCreator.cs:line 216 at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) The operation has timed out.

I am running PostgreSQL via Docker and it is active container, plus I am running pgAdmin4 as a Docker container and it is seeing PostgreSQL container.

I am probably missing something trivial, but as I said I am totally new to PostgreSQL so I can't pinpoint the cause of this error.

I would appreciate any leads.

3/25/2019 10:48:19 PM

Popular Answer

It was my mistake. I have runned docker image of PostgreSQL without opening the port to outside world. When I runned that image with -p 5432:5432, I have managed to migrate Identity Server tables to the database.

3/26/2019 1:18:30 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow