使用Add-Migration xxx时报错汇总

前言:abp中使用这个命令时,会出现比较多的问题,有无法识别的,也有缺少组件的,这里汇总以下我遇到情况,也解决下遇到同样问题的同学

报错目录:

问题1描述:使用Add-Migration xxx,控制台输出

 

1 Your target project 'xxx.EntityFrameworkCore.DbMigrations' doesn't reference EntityFramework. 
2 This package is required for the Entity Framework Core Tools to work. 
3 Ensure your target project is correct, install the package, and try again.

 

 

 

问题1解决方案:

打开NuGet,所有项目已安装的EntityFrameworkCore.Tools(下文用Tools代替)与EntityFrameworkCore.Design(下文用Design代替)卸载,DbMigrations重新安装Tools与Design,保证EntityFrameworkCore.Tools与EntityFrameworkCore.Design版本对应,过程中可能要求其他层安装Tools与Design,根据提示的错误说那个项目缺少引用就引用Tools或者Design。


问题1备注:解决Tools与Design后,可能会出现

 

复制代码
 1 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 3  ---> System.TypeLoadException: Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
 5    at Microsoft.Extensions.DependencyInjection.SqlServerServiceCollectionExtensions.AddEntityFrameworkSqlServer(IServiceCollection serviceCollection)
 7    at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension.ApplyServices(IServiceCollection services)
 9    at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services)
11    at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
13    at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
15    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
17    at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
19    at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
21    at Volo.Abp.EntityFrameworkCore.AbpDbContext`1..ctor(DbContextOptions`1 options)
23    at Pro212.EntityFrameworkCore.DbMigrations.EntityFrameworkCore.Pro212MigrationsDbContext..ctor(DbContextOptions`1 options) in D:\abp\Pro212\src\Pro212.EntityFrameworkCore.DbMigrations\EntityFrameworkCore\Pro212MigrationsDbContext.cs:line 11
25    at Pro212.EntityFrameworkCore.DbMigrations.EntityFrameworkCore.Pro212MigrationsDbContextFactory.CreateDbContext(String[] args) in D:\abp\Pro212\src\Pro212.EntityFrameworkCore.DbMigrations\EntityFrameworkCore\Pro212MigrationsDbContextFactory.cs:line 20
27    --- End of inner exception stack trace ---
29    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
31    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
33    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
35    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContextFromFactory(Type factory, Type contextType)
37    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass16_0.<FindContextFactory>b__1()
39    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
41    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
43    at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
45    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
47    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
49    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
51    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
53 Exception has been thrown by the target of an invocation.
复制代码

 

此错误说EntityFrameworkCore.SqlServer版本问题,重新安装EntityFrameworkCore.SqlServer,同样与Tools与Design版本对应即可。

 

其他错误待更新。

 

posted @   0Behavior  阅读(1868)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示