简体   繁体   English

在MVC5中运行Update-Database时出错

[英]Error while running Update-Database in MVC5

I have a MVC 5 app, that has MySQL database hosted in Azure. 我有一个MVC 5应用程序,它在Azure中托管了MySQL数据库。 It was working all well, but today when I tried to type Update-Database and run it, I got the following error message: 它运行良好,但今天当我尝试键入Update-Database并运行它时,我收到以下错误消息:

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.

What can be the problem, and how can I solve it? 可能是什么问题,我该如何解决?

I had this problem before: 我以前遇到过这个问题:

1.- Install an update the mysql connector to the new version: http://dev.mysql.com/downloads/connector/net/ 1.-将mysql连接器的更新安装到新版本: http//dev.mysql.com/downloads/connector/net/

2.- Because you are trying to connect to a remote installation of MySQL you have to make sure that the port is open. 2.-因为您尝试连接到MySQL的远程安装,您必须确保端口是打开的。 You can try to connect to a local MySQL DB to verify this. 您可以尝试连接到本地MySQL数据库来验证这一点。

I hope this work for you too. 我希望这也适合你。

Just in case someone else stumbled upon this "Type is not resolved for member" error: 以防其他人偶然发现这个“Type is not resolved for member”错误:

This message is very misleading because it is shown for many issues that have nothing to do with what you may assume from this message. 此消息非常具有误导性,因为它显示的许多问题与您从此消息中可能假设的内容无关。

Most of the time I was running into into this message it was some code within a mapped class throwing an exception while the Seed method was executing. 大多数时候我遇到这个消息,它是一个映射类中的一些代码,在Seed方法执行时抛出异常。 Watch out for custom ToString() and GetHashCode() implementations. 注意自定义ToString()和GetHashCode()实现。

The VS debugger is your best friend in this case. 在这种情况下,VS调试器是你最好的朋友。 Just add the following code to your Seed() method: 只需将以下代码添加到Seed()方法:

   if (System.Diagnostics.Debugger.IsAttached == false)
      System.Diagnostics.Debugger.Launch();

Launch a second VS instance with your project before running the Update-Database command and you should see what is wrong. 在运行Update-Database命令之前,使用项目启动第二个VS实例,您应该看到错误。

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

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