【问题标题】:EF Core 5.0.5 Add-Migration The string argument 'name' cannot be emptyEF Core 5.0.5 Add-Migration 字符串参数“名称”不能为空
【发布时间】:2021-07-26 09:08:35
【问题描述】:

我遇到了关于Add-Migration 的问题,并给了我一个错误The string argument 'name' cannot be empty.。我试着像这样执行这个命令:Add-Migration Update_Add_User.

这是错误:

构建开始... 构建成功。 System.ArgumentException:字符串参数“名称”不能为空。 在 Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(字符串值,字符串参数名称) 在 Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.Identifier(字符串名称,ICollection1 scope) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(CreateTableOperation operation, IndentedStringBuilder builder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList1 操作,IndentedStringBuilder 生成器) 在 Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(字符串迁移名称空间,字符串迁移名称,IReadOnlyList1 upOperations, IReadOnlyList1 downOperations) 在 Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(字符串迁移名称、字符串根命名空间、字符串子命名空间、字符串语言) 在 Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(字符串名称、字符串 outputDir、字符串 contextType、字符串命名空间) 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(字符串名称,字符串 outputDir,字符串 contextType,字符串命名空间) 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.c__DisplayClass0_0.<.ctor>b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.c__DisplayClass3_0`1.b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(操作动作) 字符串参数“名称”不能为空。

谁能告诉我如何解决这个问题?

更新:Nuget 包

Microsoft.EntityFrameworkCore 5.0.5 Microsoft.EntityFrameworkCore.SqlServer 5.0.5 Microsoft.EntityFrameworkCore.Design 5.0.5

【问题讨论】:

  • 你能像Add-Migration Update-Add-User那样试试吗?
  • 添加的表的定义/映射中似乎有些东西使 EF Core 感到困惑。如果有的话,你能显示User类和相关的流畅配置吗?
  • 所以抛出了异常github.com/dotnet/efcore/blob/v5.0.5/src/EFCore.Design/…,因为你的列名之一是空的?

标签: c# entity-framework-core


【解决方案1】:

确保添加 nuget 包 Microsoft.EntityFrameworkCore.Tools,否则您将无法在包管理器控制台上运行 EF 命令。

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 5.0.5

如果你使用过,你会得到同样的错误吗 dotnet ef add-migration nameOfMigration?

【讨论】:

猜你喜欢
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 2019-05-13
  • 1970-01-01
  • 2017-08-07
  • 2016-11-04
相关资源
最近更新 更多