我第一次将实体框架核心迁移到我的平均大小项目(大约 100 个表),现在我正在尝试使用包管理器控制台中的"更新数据库"调用对 azure sql 数据库进行更改。
我将始终收到此错误: 异常消息: 堆栈跟踪:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler, Microsoft.EntityFrameworkCore.Design, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Server stack trace:
at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod(Boolean bThrowIfNotResolved)
at System.Runtime.Remoting.Messaging.MethodCall..ctor(SmuggledMethodCallMessage smuggledMsg, ArrayList deserializedArgs)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.EntityFrameworkCore.Design.IOperationResultHandler.OnError(String type, String message, String stackTrace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor.Execute(String operationName, Object resultHandler, IDictionary arguments)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.InvokeOperationImpl(String operationName, IDictionary arguments)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.UpdateDatabase(String migration, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Commands.DatabaseUpdateCommand.Execute()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.
我知道它尝试删除此表主键 - 在此之前有多个类似的调用:
migrationBuilder.DropPrimaryKey(name: "pk_usr", table: "usr");
我的问题可能是什么原因 - 感谢您的帮助!
参考我所拥有的(都是 1.1.1.0):
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Relational
Microsoft.EntityFrameworkCore.Relational.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design
检查这是否可以解决您的问题,如果没有,请继续以下选项 EF 工具 1.1.0-preview4 无法识别的选项"--config" #7071
- 您是否正在尝试更新已创建的数据库?如果是这样, 您的迁移可能与迁移数据库不同步 快照。您以前没有创建数据库表 迁移和/或添加或删除列或表而不使用 迁移,忘记使用当前迁移并创建新的迁移 数据库。
- 其他一些原因可能是您在 类库,这目前不起作用;
- 另一个原因可能是使用某些包的 .Net Core 运行时 由于可能的更新,当前未引用,因此请确保 您正在使用引用的包 或者
- 可能是,你更新了解决方案,或者你的解决方案已使用 已安装的 .NET 不支持的更新的 NuGet 包 核心运行时。叮叮当当,反之亦然。
看起来您使用的是不兼容的Microsoft.EntityFrameworkCore.Tools
版本。确保已安装版本 1.1.0。