从EF Core 2.1升级到3.1后,无法在项目之间进行数据库迁移

问题描述

我一直在使用

dotnet ef --startup-project "../WebApp/WebAppProject/" migrations add migrationName

生成迁移,但是在将EF Core版本从2.1升级到3.1之后,它开始引发如下错误

An error occurred while accessing the Microsoft.Extensions.Hosting 
services. 

Continuing without the application service provider.

Error: Problem with determining the path to the folder storing the application files
System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,System.Object>>)'.
at 

位于{p的base.OnModelCreating(builder);

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

    builder.ApplyConfigurationsFromAssembly(typeof(Context).Assembly);
}

我的项目/文件夹结构

Container
|
|
|----- Common (project) (here I'm executing above mentioned command as I used to do it)
            |
            |
            |
            |----- Persistence
                             |
                             |
                             | Context.cs
                             | ----- Migrations
                                              |
                                              | Migration1.cs
                                              | Migration2.cs
                                              | Migration3.cs
                                              | ....cs
|
| ----- WebApp
             | ----- WebAppProject (project)
                        | WebApp.csproj
                        | Startup.cs
                        | Program.cs
            
            

DesignTimeDbContextFactory类位于Program.cs内的WebApp/WebAppProject/

一般来说,路径是好的,没有任何变化,并且一直在工作,但是在升级版本后,我不确定如何帮助该工具 发现我的数据库

dotnet工具列表--global 3.1.7 dotnet-ef

解决方法

确切的命令可以有效地解决您的解决方案结构,除非您引用了某些旧库版本或正在使用某些旧的EF Core CLI版本。

请确保所有对EF Core库的引用都是最新的(表示3.1.7),并且EF Core工具也安装了相同版本。

(如果您认为已经存在,请随时发布项目文件的内容和EF Core CLI命令的--verbose输出。)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...