More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

sw
sw
34 Points
12 Posts

I'm trying to add migration but getting error:

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

Here is dbContext

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using SampleApi.Models.Entity;

namespace SampleApi.Dal
{
    public class ApiDbContext : IdentityDbContext<IdentityUser>
    {
        public ApiDbContext(DbContextOptions<ApiDbContext> options)
            : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }

        public DbSet<TodoItem> TodoItems { get; set; } = null!;
    }
}
Views: 289
Total Answered: 2
Total Marked As Answer: 1
Posted On: 04-Apr-2023 06:23

Share:   fb twitter linkedin
Answers
beginer
beginer
342 Points
91 Posts
         

Seems, multiple db contexts are there in your application code. Please review and remove any other db context.

Posted On: 05-Apr-2023 23:12
sw
sw
34 Points
12 Posts
         

Resolved issue by removing extra DBContext class.

Posted On: 07-Apr-2023 00:13
Thanks for sharing solution.
 - Rahul Maurya  07-Apr-2023 01:02
 Log In to Chat