dotnet ef migrations add fails on one DbContext succeeds on the other?

I am using EF Core v7.0.18.

I have a .csproj with 2 dBContext, GlobalDbContext and ConfiguratinDbContext.

GlobalDbContext works when I add a and EF migration – cmd lines below ConfigurationDbContext does not.

The error I get is:

Unable to create an object of type ‘ConfigurationDbContext’. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

How to fix this?

For GlobalDbContext, this works and migration is created:

dotnet ef migrations add 
--project Doma.DataLayer/Doma.DataLayer.csproj 
--startup-project Doma.DataLayer.Tests/Doma.DataLayer.Tests.csproj 
--context Doma.DataLayer.Global.Models.GlobalDbContext 
--configuration Debug 
--framework net7.0 Initial 
--output-dir Global/Migrations

For ConfigurationDbContext – this is failing:

dotnet ef migrations add --project Doma.DataLayer/Doma.DataLayer.csproj 
--startup-project Doma.DataLayer.Tests/Doma.DataLayer.Tests.csproj 
--context Doma.DataLayer.Configuration.Models.ConfigurationDbContext 
--configuration Debug --framework net7.0 Initial 
--output-dir Configuration/Migrations
    Build started...
    Build succeeded.

Unable to create an object of type ‘ConfigurationDbContext’. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Process terminated with exit code 1

Succeeding DbContext [GlobalDbContext]:

// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using Doma.DataLayer.Global.Models;
using Microsoft.EntityFrameworkCore;

namespace Doma.DataLayer.Global.Models;

public partial class GlobalDbContext : DbContext
{
    public GlobalDbContext()
    {
    }

    public GlobalDbContext(DbContextOptions<GlobalDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<AppConfiguration> AppConfigurations { get; set; }
    public virtual DbSet<FormInstance> FormInstances { get; set; }
    public virtual DbSet<FormValue> FormValues { get; set; }
   
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlite(
                "Data Source=TempGlobalDatabas.db");
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AppConfiguration>(entity =>
        {
            entity.ToTable("AppConfiguration");

            entity.Property(e => e.AppConfigurationId).HasColumnType("varchar(36)");
            entity.Property(e => e.AppName).HasColumnType("varchar");
            entity.Property(e => e.BucketName).HasColumnType("varchar");
            entity.Property(e => e.Comments).HasColumnType("varchar");
            entity.Property(e => e.ConfigurationIconPath).HasColumnType("varchar");
            entity.Property(e => e.CurrentlyInstalledVersion).HasColumnType("varchar");
            entity.Property(e => e.CurrentlyInstalledVersionLabel).HasColumnType("varchar");
            entity.Property(e => e.ETag).HasColumnType("varchar");
            entity.Property(e => e.FileKey).HasColumnType("varchar");
            entity.Property(e => e.FileName).HasColumnType("varchar");
            entity.Property(e => e.LastModified).HasColumnType("bigint");
            entity.Property(e => e.Title).HasColumnType("varchar");
            entity.Property(e => e.Url).HasColumnType("varchar");
            entity.Property(e => e.Version).HasColumnType("varchar");
        });

        modelBuilder.Entity<FormInstance>(entity =>
        {
            entity.ToTable("FormInstance");

            entity.Property(e => e.FormInstanceId).HasColumnType("varchar(36)");
            entity.Property(e => e.DateCreated).HasColumnType("bigint");
            entity.Property(e => e.FormId).HasColumnType("varchar(36)");
            entity.Property(e => e.FormInstanceName).HasColumnType("varchar");
        });

        modelBuilder.Entity<FormValue>(entity =>
        {
            entity.ToTable("FormValue");

            entity.Property(e => e.FormValueId).HasColumnType("varchar(36)");
            entity.Property(e => e.FormInstanceId).HasColumnType("varchar(36)");
            entity.Property(e => e.QuestionId).HasColumnType("varchar");
            entity.Property(e => e.Type).HasColumnType("varchar");
            entity.Property(e => e.Value).HasColumnType("varchar");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable

Failing DbContext (ConfigurationDbContext):

// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using Doma.DataLayer.Global.Models;
using Microsoft.EntityFrameworkCore;

namespace Doma.DataLayer.Global.Models;

public partial class GlobalDbContext : DbContext
{
    public GlobalDbContext()
    {
    }

    public GlobalDbContext(DbContextOptions<GlobalDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<AppConfiguration> AppConfigurations { get; set; }

    public virtual DbSet<FormInstance> FormInstances { get; set; }
    public virtual DbSet<FormValue> FormValues { get; set; }
   
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlite(
                "Data Source=TempGlobalDatabas.db");
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AppConfiguration>(entity =>
        {
            entity.ToTable("AppConfiguration");

            entity.Property(e => e.AppConfigurationId).HasColumnType("varchar(36)");
            entity.Property(e => e.AppName).HasColumnType("varchar");
            entity.Property(e => e.BucketName).HasColumnType("varchar");
            entity.Property(e => e.Comments).HasColumnType("varchar");
            entity.Property(e => e.ConfigurationIconPath).HasColumnType("varchar");
            entity.Property(e => e.CurrentlyInstalledVersion).HasColumnType("varchar");
            entity.Property(e => e.CurrentlyInstalledVersionLabel).HasColumnType("varchar");
            entity.Property(e => e.ETag).HasColumnType("varchar");
            entity.Property(e => e.FileKey).HasColumnType("varchar");
            entity.Property(e => e.FileName).HasColumnType("varchar");
            entity.Property(e => e.LastModified).HasColumnType("bigint");
            entity.Property(e => e.Title).HasColumnType("varchar");
            entity.Property(e => e.Url).HasColumnType("varchar");
            entity.Property(e => e.Version).HasColumnType("varchar");
        });

        modelBuilder.Entity<FormInstance>(entity =>
        {
            entity.ToTable("FormInstance");

            entity.Property(e => e.FormInstanceId).HasColumnType("varchar(36)");
            entity.Property(e => e.DateCreated).HasColumnType("bigint");
            entity.Property(e => e.FormId).HasColumnType("varchar(36)");
            entity.Property(e => e.FormInstanceName).HasColumnType("varchar");
        });

        modelBuilder.Entity<FormValue>(entity =>
        {
            entity.ToTable("FormValue");

            entity.Property(e => e.FormValueId).HasColumnType("varchar(36)");
            entity.Property(e => e.FormInstanceId).HasColumnType("varchar(36)");
            entity.Property(e => e.QuestionId).HasColumnType("varchar");
            entity.Property(e => e.Type).HasColumnType("varchar");
            entity.Property(e => e.Value).HasColumnType("varchar");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
    

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật