添加迁移时出现“值不能为 null。参数名: language”的错误。

11

我正在尝试创建新的迁移,但出现了System.ArgumentNullException错误,错误信息如下:

System.ArgumentNullException: Value cannot be null.
Parameter name: language
    at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, 
    String parameterName)
    at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor
    (IOperationReporter reporter, Assembly assembly, Assembly 
    startupAssembly, String projectDir, String rootNamespace, String 
    language)
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ct
    or>b__4()
    at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: language

1
它们不是相同的。 - Bug
请提供您正在添加的模型。 - Alexey Klipilin
5个回答

10

这是问题#11075。您的工具版本与运行时版本不匹配。请确保已将所有Microsoft.EntityFrameworkCore包更新为2.1.0-preview1-final。


可能在脚手架和迁移中有不同的代码路径?我在进行数据库迁移时遇到了错误。只是说对我来说,问题似乎是由2.1.0 Final引入的一个错误。降级到2.0.1将解决我的迁移问题。在11075问题中添加了详细的重现步骤说明。 - Dano
3
对我来说,未更新的软件包是 csproj 文件中的 <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.1.0-preview1-final" />。 - animalito maquina
@animalitomaquina - 是的,这对我来说也是如此。谢谢!目前我需要这个版本,因为v2.0.2不支持环境事务。 - code5
谢谢,这个问题即使在EF6中也存在,但是只要我将所有项目引用更新到最新版本的EF(目前为6.4.4),它就帮了我。 - curiousBoy

6

这与 EF Core 而非 EF6 有关,看起来 2.1.0.preview1-final 版本存在一个 bug。

  • 使用 dotnet ef --version 命令检查你正在运行的版本号。
  • 将 Microsoft.EntityFrameworkCore.Design 版本降级至 2.0.1。

谢谢,这个问题让我困扰了一段时间。 - Scott Alexander

2

0
在VS 2017版本15.7.1中,针对.NET Core 2.0.1的EF Core,我从项目文件中删除了DotNetCliToolReference元素。

enter image description here

enter image description here


0

我认为这是一个bug。
我正在使用EF Core 2.2.4,尝试使用以下命令回滚迁移:

migrationBuilder.DropIndex(name: "myIndexName");

这是由 EF 自动为我生成的。
方法签名表示名称是唯一必需的参数(之后有两个可选参数)。 当我运行此代码时,我得到了以下结果:

System.ArgumentNullException: Value cannot be null.
Parameter name: name

但是如果我为表名添加第二个参数,它就可以工作:

migrationBuilder.DropIndex(
                name: "myIndexName",
                table: "myTableName");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接