在程序集“ProjectName”中找不到迁移配置类型

问题描述 投票:0回答:2

我正在尝试更新我的数据库和添加迁移。我收到以下错误:

PM>添加-迁移更新

在程序集“基础设施”中找不到迁移配置类型。 (在 Visual Studio 中,您可以使用包管理器控制台中的 Enable-Migrations 命令来添加迁移配置)。

PM>启用迁移

在程序集“基础设施”中找不到上下文类型。

DbContext 位于基础设施内部。 我之前有五次迁移均已完成且没有错误。在上次迁移和我现在尝试的迁移之间,我没有更改我的 DbContext 方法。

基础设施.数据:

namespace Infrastructure.Data
{
    public class MovieshopDBContext : DbContext
    {
        //will generate the DB tables
        public MovieshopDBContext(DbContextOptions<MovieshopDBContext> options) :base(options)
        {
            //specify options

            
        }
        public DbSet<Genre> Genres { get; set; }
        public DbSet<Movie> Movies { get; set; }
        public DbSet<Trailer> Trailers { get; set; }
        public DbSet<Cast> Casts { get; set; }
        public DbSet<Crew> Crews { get; set; }
        public DbSet<Favorite> Favorites { get; set; }
        public DbSet<MovieCast> MovieCasts { get; set; }
        public DbSet<MovieCrew> MovieCrews { get; set; }
        public DbSet<MovieGenre> MovieGenres { get; set; }
        public DbSet<Purchase> Purchases { get; set; }
        public DbSet<Review> Reviews { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }

    }
}

我相信已安装所有必需的依赖项和 NuGet 包。 我尝试过的事情: 重建,使用 -force 重新运行命令。 重新启动机器。 检查了 Microsoft.docs.com

c# sql database
2个回答
1
投票

经过几个小时的搜索,我找到了答案:

致谢:Henryk Budzinski on SO

  1. 从解决方案中的所有项目中删除 EntityFramework(而非 EntityFrameworkCore)引用
  2. 在资源管理器(Windows 资源管理器)中打开解决方案文件夹
  3. 关闭VS
  4. 删除.vs文件夹
  5. 再次打开解决方案
  6. 运行 update-database,警报消失了

完美地为我工作。


0
投票

在我使用 Package EntityFrameworkCore 6.0.4 的情况下,只需关闭 Visual Studio 并删除解决方案目录中隐藏的 .vs 文件夹即可解决。

额外的陷阱: 始终确保通过 CLI 或在 Package Manager Console 中选择数据层项目来指定正确的目标项目。

© www.soinside.com 2019 - 2024. All rights reserved.