使用Add-Migration无法添加多个迁移(Pomelo.EntityFrameworkCore.MySql)
Pomelo EF Core MySQL 添加迁移时触发空引用异常
问题描述
使用程序包管理器控制台的Add-Migration命令添加新迁移或空迁移时,触发空引用异常。
重现步骤
- 项目中已存在迁移文件
- 在程序包管理器控制台执行命令
Add-Migration Test添加新迁移,或尝试添加空迁移
技术细节
- MySQL版本:8.0.32 MySQL Community Server
- 操作系统:Windows 10 22H2
- Pomelo.EntityFrameworkCore.MySql版本:7.0.0
- Microsoft.AspNetCore.App版本:6.0
已尝试方案
- 更换为MySql.Data/MySql.EntityFrameworkCore驱动后,迁移可正常执行,但无法将Blob数据保存至数据库
- 考虑采用双驱动方案,分别管理数据库结构与数据,已在Pomelo相关仓库提交对应问题
堆栈跟踪
System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.InitializeColumnHelper(ColumnOperation columnOperation, IColumn column, Boolean inline) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext() at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.MakeStringColumnsRequiredWithoutUnexpectedDefaultValue(IColumn source, IColumn target, IEnumerable`1 migrationOperations)+MoveNext() at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.SkipRedundantCharSetSpecifyingAlterColumnOperations(IEnumerable`1 migrationOperations)+MoveNext() at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.PostFilterOperations(IEnumerable`1 migrationOperations)+MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext() at System.Linq.Enumerable.ConcatIterator`1.MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext() at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.PostFilterOperations(IEnumerable`1 migrationOperations)+MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext() at System.Linq.Enumerable.ConcatIterator`1.MoveNext() at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.PostFilterOperations(IEnumerable`1 migrationOperations)+MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext) at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Object reference not set to an instance of an object.
内容的提问来源于stack exchange,提问作者M. Ours
相关产品推荐
相关产品推荐

