Core添加迁移时出现错误

Core添加迁移时出现错误

本文介绍了使用Entity Framework Core添加迁移时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个控制台项目,并首先使用代码将模型映射到数据库.当我运行 Add-Migration InitialMigration 的命令时,出现错误:

I built a console project and use code first to map model to database. When I run the command of Add-Migration InitialMigration, I get an error:

DbContext 是:

class ActorDbContext : DbContext
{
    public DbSet<Actor> Actors { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(
            @"Server=(localdb)\mssqllocaldb;Database=ActorDb;"
            + "Trusted_Connection=True;");
    }
}

实体为:

public class Actor
{
    public int Id { get; set; }
    public String Name { get; set; }
    public int Age { get; set; }
    public bool AcademyWinner { get; set; }
}

推荐答案

我只是使用 VS for Mac 遇到了同样的问题.我的问题是我安装了以下版本的软件包:

I just ran into this same issue using VS for Mac.My problem was I had the following versions of packages installed:

记下使用的不同版本.为了解决此问题,我卸载了软件包的 preview 版本并安装了最新的稳定版本.

Take note of the different versions used.To correct the issue I uninstalled the preview versions of the packages and installed the latest stable versions.

再次记下所有3个软件包的版本.一旦我为每个软件包安装了正确的版本,问题就解决了,我的 Add-Migration 工作了.

Again take note of the versions for all 3 packages.Once I had installed the correct version of each package the issue was resolved and my Add-Migration worked.

这篇关于使用Entity Framework Core添加迁移时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 22:14