Home > Software design >  Value cannot be null error when attempting migration w/ .NET EF
Value cannot be null error when attempting migration w/ .NET EF

Time:12-30

I am running into a "Value cannot be null" error when trying to run the following command "dotnet ef migrations add InitialCreate -p Persistence -s API/"

I don't know if it matters or not, but I am following a class that is using .net 5.0 and I am using .net 6.0; but I have made modifications to the project as they have been recommended in the class to make it work for 6.0.

I have attached a screen shot of the Console Output here -> 1

One of the first lines of the console output seems to point to my Startup script

 public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPIv5", Version = "v1" });
        });
        services.AddDbContext<DataContext>(opt =>
        {
            opt.UseSqlite(_config.GetConnectionString("Default Collection")); <-- this line is referenced by the output.
        });
    }

I am not quite sure to do, and VSCode is not throwing any errors or warnings in regards to this code.

TIA

CodePudding user response:

I can't comment, so here's an answer.


Are you sure you don't have a simple spelling mistake?

The program is looking for a connection string with the name Default Collection (with two "l"s)

Your update comment states that you have Default Connection (with two "n"s) defined.

I would start by verifying that they match exactly.

  • Related