繁体   English   中英

EF Core 删除迁移错误:Object 引用未设置为 object 的实例

[英]EF Core Remove-Migration error: Object reference not set to an instance of an object

自从我开始使用 EF 核心 3.0 以来,每当我想恢复迁移时,我都会遇到 null 引用异常。 添加迁移没有任何错误,但运行删除迁移,我得到一个 null 引用异常。 虽然删除了迁移文件,但是 ContextModelSnapshot.cs 文件中的迁移内容没有被删除,我想这是由于 null 引用异常不允许删除迁移过程成功完成。

注意:我的任何实体框架配置中也没有 HasComment。

任何人都知道我可以如何解决这个错误。

System.NullReferenceException:Object 引用未设置为 object 的实例。 在 Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.Literal(String value) 在 Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GeneratePropertyAnnotations(IProperty 属性,IndentedStringBuilder stringBuilder) 在 Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperty(String builderName , IProperty 属性, IndentedStringBuilder stringBuilder) 在 Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperties(String builderName, IEnumerable 1 properties, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList 1 entityTypes, IndentedStringBuilder stringBuilder) Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateSnapshot(String modelSnapshotNamespace, Type contextType, String modelSnapshotName, IModel model) at Microsoft.EntityFrameworkCore.Migrations. (String projectDir, String rootNamespace, Boolean force, String language) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Object 引用未设置为 object 的实例。

现在不确定这个问题是否真实,但是当我从 EF core 2.x 更新到 3.x 时,我遇到了同样的问题。 EF Core 3.0 中有一些重大变化:

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/break-changes#microsoftentityframeworkcoredesign-is-now-a-developmentdependency-package

我通过删除 package 参考并改用 Microsoft.EntityFrameworkCore.Tools 3.1.1 来解决我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM