【问题标题】:specify appsettings while adding database migration添加数据库迁移时指定 appsettings
【发布时间】:2017-10-03 17:26:09
【问题描述】:

appsettings 文件

  1. appsettings.json
  2. appsettings.Production.json
  3. appsettings.Test.json
  4. appsettings.Debug.json

全部针对特定环境,但首先针对通用设置。

appsettings.json 文件不包含连接字符串,因为每个环境都有自己的数据库。

运行add-migration mig-1 显然会抱怨

找不到名为“ConnectionString”的连接字符串。

如何指定连接字符串取自 appsettings.Test.json 而不是默认的 (appsettings.json)

【问题讨论】:

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


    【解决方案1】:

    docs找到答案

    add-migration mig-1 -e Test    
    

    注意

    EF Core 1.x CLI 工具支持一个名为 environment 的参数,该参数可用于在针对 ASP.NET Core 应用程序运行命令时指定环境。此参数在 2.0 中不再可用:

    -e|--environment <NAME>  The environment to use. Defaults to "Development".
    

    在 2.0 中,您可以改用 ASPNETCORE_ENVIRONMENT 环境变量。

    【讨论】:

    • 仅供参考,在 EF Core 2.0.0 中,您需要设置 ASPNETCORE_ENVIRONMENT 环境变量。
    猜你喜欢
    • 2014-10-18
    • 2018-03-04
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2014-12-25
    • 1970-01-01
    相关资源
    最近更新 更多