0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ASP.NET core + EF core コマンド「add-migration」にてエラー:Cannot resolve scoped service~ from root provider.

Posted at

環境:ASP.NET core 3.1, Visual Studio 2019

以下の通り、同じDbContextを2つ登録していたのが原因。
InMemoryの方を消したら通った。

    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // InMemory
            services.AddDbContext<AppDbContext>(options =>
                options.UseInMemoryDatabase(nameof(AppDbContext))
                .ConfigureWarnings(m => m.Ignore(InMemoryEventId.TransactionIgnoredWarning))
                );

            // Postgres
            services.AddDbContextPool<AppDbContext>(options =>
            {
                options.UseNpgsql(Configuration.GetConnectionString(typeof(AppDbContext).Name));
            });
省略
        }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?