【问题标题】:EF-core with PostgreSQL migration error带有 PostgreSQL 迁移错误的 EF-core
【发布时间】:2018-08-01 13:35:19
【问题描述】:

在我的 appsettings.json 中:

{
  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Host=localhost;Username={{postgres}};Password={{postgres}};Database={{asp_trial_api}};Port=5432;Pooling=true;"
    }
},
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

在我的 startup.cs 中:

 public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddDbContext<WebAPIDataContext>(options => {
                options.UseNpgsql(Configuration["Data:DefaultConnection:ConnectionString"]);
            });

            services.AddMvc();
            services.AddSwaggerGen();
        }

我的dotnet ef migrations add initial成功了,但是dotnet ef database update给了我以下错误:

28P01: password authentication failed for user "{{postgres}}"

我在连接字符串中提供的用户名和密码是正确的。我已经在我的 PostgresSQL 中创建了一个名为 asp_trial_api 的空白数据库。

这里出了什么问题?

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc entity-framework-core


    【解决方案1】:

    问题似乎在连接字符串中缺少一些属性,例如User IDServer。试试下面的 CS

    "ConnectionStrings": {
        "DefaultConnection": "User ID=postgres;Password={{pass}};Server=localhost;Port=1234;Database={{database}};Integrated Security=true;Pooling=true;"
    },
    

    我有一个GitHub Repo 用于一个带有 Postgres 数据库的 ASP.NET Core 应用程序的工作示例。

    【讨论】:

    • 这看起来很有希望,但它给了我No connection could be made because the target machine actively refused it 错误。可能的原因?我删除了数据库 asp_trial_api 并创建了一个新的 api_trial 并刷新了所有内容。
    • 连接字符串中的服务器端口和用户名是否配置正确?我也有同样的问题,但我知道User ID 是正确的(在我的情况下)。你能仔细检查一下吗?
    • 也将我刚才提供的连接字符串替换为你的,修改数值看看是否有效!
    • 是的,实际上我复制了您的字符串并忘记更新端口号。现在我设置为我的端口号,但后来它把我扔了28P01: password authentication failed for user "postgres"
    • 您在登录您的 PostgreSQL 服务器时使用任何密码吗?
    猜你喜欢
    • 1970-01-01
    • 2020-09-09
    • 2021-12-29
    • 2021-09-30
    • 1970-01-01
    • 2021-11-23
    • 2018-07-06
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多