0
respostas

Erro ao executar Update-Database com PostgresSql

Bom dia.

Ao executar o comando Update-Database, esta retornando o seguinte erro:

PM> Add-Migration CriarTabelaExames Build started... Build succeeded. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 6.0.1 initialized 'ExameContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL:6.0.3+94d0a8eaeb9cf5af6ce55a9e59153c1a1be3244f' with options: None To undo this action, use Remove-Migration. PM> Update-Database Build started... Build succeeded. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 6.0.1 initialized 'ExameContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL:6.0.3+94d0a8eaeb9cf5af6ce55a9e59153c1a1be3244f' with options: None System.ArgumentException: Couldn't set user (Parameter 'user') ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at Npgsql.NpgsqlConnectionStringBuilder.GeneratedSetter(String keyword, Object value) at Npgsql.NpgsqlConnectionStringBuilder.set_Item(String keyword, Object value) --- End of inner exception stack trace --- at Npgsql.NpgsqlConnectionStringBuilder.set_Item(String keyword, Object value) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at Npgsql.NpgsqlConnectionStringBuilder..ctor(String connectionString) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists() 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 connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Couldn't set user (Parameter 'user') PM>

Abaixo a configuração do meu appsettings.json:

{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "ExamesConnection" : "server=localhost:database=ExamesDb;user=root;password=123" } }

Abaixo a configuração do meu Startup:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ExameContext>(opts => opts.UseNpgsql(Configuration.GetConnectionString("ExamesConnection")));
        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "ExamesAPI", Version = "v1" });
        });
    }