asp.net core 2.0 - Value cannot be null. Parameter name: connectionString

后端 未结 22 1871
时光取名叫无心
时光取名叫无心 2020-12-13 10:00

I had the following error in package manager console when Add-Migration

Value cannot be null. Parameter name: connectionString

相关标签:
22条回答
  • 2020-12-13 10:07

    I found my own problem.

    I have an AppDbContextFactory class which inherits IDesignTimeDbContextFactory. Deleting this class resolves this issue.

    0 讨论(0)
  • 2020-12-13 10:07

    Another scenario can be where you set the configuration. set the connection string in appsettings.json instead of appsettings.Development.json

    0 讨论(0)
  • 2020-12-13 10:07

    I figured I would add what it was for me. I had followed a popular tutorial to add appsettings.json and dependency injection to a console application. I did not realize in the setup that it referenced the current directory and was using that to set the base path of the configuration builder. It worked fine when I was running locally, but as soon as I tried to deploy and have a SQL scheduled job run the command it was taking the directory where the command was being entered, not where the DLL was so it wasn't finding my appsettings.json file. I simply removed the lines that dealt with getting the current directory and setting that as the base path and it works fine. It seems like it defaults to the same folder as the DLL.

    0 讨论(0)
  • 2020-12-13 10:10

    For me it was that I had appSettings.json instead of appsettings.json for some reason (not quite sure if VS did that with a newly created project or I had renamed it to that). Once I changed the name, it worked fine.

    0 讨论(0)
  • 2020-12-13 10:12

    I had the same error and resolved it by moving "ConnectionStrings" to be the first variable in the appsettings.json file.

    0 讨论(0)
  • 2020-12-13 10:14

    If you have previously renamed your connection string in appsettings file and you have omitted to rename it in DesignTimeDbContextFactory class (if you have it in your project) and that is checked by Entity framework, then you may run in this issue.

    0 讨论(0)
提交回复
热议问题