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
170 Points
7 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: 1260
Total Answered: 3
Total Marked As Answer: 1
Posted On: 04-Apr-2023 06:23

Share:   fb twitter linkedin
Answers
beginer
beginer
1544 Points
52 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
170 Points
7 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
Priya
Priya
1194 Points
33 Posts
         

Helped a lot

Posted On: 10-Feb-2024 00:41
 Log In to Chat