Error add-Migration . net core 3

Asked

Viewed 607 times

0

I am trying to add the add-Migration in my solution but always happens the following error "Value cannot be null (Parameter 'connectionString')"

but my connection string is correct in appsettings.json inserir a descrição da imagem aqui

  public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddDbContext<SimCoContext>(optBuilder =>
        optBuilder.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
}

Appsettings.json

{
  "ConnectionsStrings": {
    "DefaultConnection": "Host=localhost;Port=5432;Pooling=true;User ID=postgres;Password=admin;Database=SimCo;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
  • Choose to put the code instead of the image when placing code. I believe it is misspelled in line 2 the Connectionstring

  • Probably your error is in the Startup class where you indicate the connection string in the configure service method you must indicate "Defaultconnection".

2 answers

0


0

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddDbContext<SimCoContext>(optBuilder =>
        optBuilder.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
}

Appsettings.json

{
  "ConnectionsStrings": {
    "DefaultConnection": "Host=localhost;Port=5432;Pooling=true;User ID=postgres;Password=admin;Database=SimCo;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
  • 1

    Put that in the question, here are the answers ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.