title: No database provider has been configured for this DbContext in .net 6 preview 7
body: <p>I'm using .net 6, and when I tried to do a migration, I had a problem:</p>
  <blockquote>
  <p>No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.</p>
  </blockquote>
  <p>I read another 6 question in Stack, but although the error message is the same not the solutions or the problems seems to be the same, I think the problem is related to .net 6 preview 7, help me find a solution.</p>
  <p>I Have 3 projects</p>
  <blockquote>
  <p>Jupyter.Core.Api -&gt; Has DbConfiguration</p>
  </blockquote>
  <blockquote>
  <p>Jupyter.Core.Data -&gt; Has DbContext</p>
  </blockquote>
  <blockquote>
  <p>Jupyter.Core -&gt; Has 1 Model</p>
  </blockquote>
  <p>And</p>
  <blockquote>
  <p>Jupyter.Core.Api references Jupyter.Core.Data</p>
  </blockquote>
  <blockquote>
  <p>Jupyter.Core.Data references Jupyter.Core</p>
  </blockquote>
  <p>In Jupyter.Core.Api I have the following PackageReference relate to the problem:</p>
  <pre><code>&lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Tools&quot; Version=&quot;5.0.9&quot;&gt;
    &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
    &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
  &lt;/PackageReference&gt;
  &lt;PackageReference Include=&quot;Npgsql&quot; Version=&quot;5.0.7&quot; /&gt;
  &lt;PackageReference Include=&quot;Npgsql.EntityFrameworkCore.PostgreSQL&quot; Version=&quot;5.0.7&quot; /&gt;
  </code></pre>
  <p>In Jupyter.Core.Data I have the following PackageReference relate to the problem:</p>
  <pre><code>&lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore&quot; Version=&quot;6.0.0-preview.7.21378.4&quot; /&gt;
  </code></pre>
  <p>In the Jupyter.Core.Api inside Program.cs my code is like this, there is no Startup.cs in .net 6 template</p>
  <pre><code>using Jupyter.Core.Data;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.OpenApi.Models;
  
  var builder = WebApplication.CreateBuilder(args);
  
  // Add services to the container.
  
  builder.Services.AddControllers();
  
  builder.Services.AddDbContext&lt;StationContext&gt;(options =&gt; options.UseNpgsql(builder.Configuration.GetConnectionString(&quot;StationConnection&quot;)));
  
  builder.Services.AddSwaggerGen(c =&gt;
  {
      c.SwaggerDoc(&quot;v1&quot;, new() { Title = &quot;Juptyer.Core.Api&quot;, Version = &quot;v1&quot; });
  });
  
  var app = builder.Build();
  
  // Configure the HTTP request pipeline.
  if (builder.Environment.IsDevelopment())
  {
      app.UseDeveloperExceptionPage();
      app.UseSwagger();
      app.UseSwaggerUI(c =&gt; c.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;Juptyer.Core.Api v1&quot;));
  }
  
  app.UseHttpsRedirection();
  
  app.UseAuthorization();
  
  app.MapControllers();
  
  app.Run();
  </code></pre>
  <p>And in Jupyter.Core.Data the StationContext.cs is like this.</p>
  <pre><code>using System;
  using Jupyter.Core.Models;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore.Metadata;
  
  #nullable disable
  
  namespace Jupyter.Core.Data;
  
  public partial class StationContext : DbContext
  {
      public StationContext() { }
  
      public StationContext(DbContextOptions&lt;StationContext&gt; options) : base(options) { }
  
      protected override void OnConfiguring(DbContextOptionsBuilder opitionsBuilder)
      {
          base.OnConfiguring(opitionsBuilder);
      }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.HasAnnotation(&quot;Relational:Collation&quot;, &quot;en_US.utf8&quot;);
  
          OnModelCreatingPartial(modelBuilder);
      }
  
      partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  
      public DbSet&lt;User&gt; Users { get; set; }
  }
  </code></pre>
  <p>I using Visual Studio, I trying the fallowing command in package console.</p>
  <blockquote>
  <p>add-migration 'User' -Context StationContext</p>
  </blockquote>
  <p>My default startup project is set to Jupyter.Core.Api and inside the package console is set to Jupyter.Core.Data.</p>
  <p>The message talk about, No database provider has been configured for this DbContext, but I did it in Program.cs</p>
  <pre><code>builder.Services.AddDbContext&lt;StationContext&gt;(options =&gt; 
      options.UseNpgsql(builder.Configuration.GetConnectionString(&quot;StationConnection&quot;)));
  </code></pre>
  <p>It also talks about &quot;If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.&quot; and I also did that.</p>
  <pre><code>protected override void OnConfiguring(DbContextOptionsBuilder opitionsBuilder)
  {
      base.OnConfiguring(opitionsBuilder);
  }
  </code></pre>
  <p>I also know that DbContext class should have a contructor like this.</p>
  <pre><code>public StationContext(DbContextOptions&lt;StationContext&gt; options) : base(options) { }
  </code></pre>
  <p>So, what I'm missing? any hint?</p>