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

后端 未结 22 1917
时光取名叫无心
时光取名叫无心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 10:16

    I had the same problem and what it is the I had to make sure that the name of the connection matches:

          services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddDbContext(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
    

    which ****ConnectionStrings:DefaultConnection*** it was where I had the whole problem. Make sure that is the same in Startup.cs and appsettings.json(appsettings.Development.json in Vs 2019)

    After I fixed this, everything was fine.

提交回复
热议问题