使用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 @ 2021-02-01 16:01  0Behavior  阅读(1830)  评论(0编辑  收藏  举报