实体框架无法使用二进制数组添加迁移
Entity Framewok Failed adding migration with binary array
我一直在项目中使用 EF 6.0 CodeFirst 并成功添加了一些迁移,但现在我有一个我无法应用的新迁移。这是脚手架迁移:
public partial class FileContentByteArray : DbMigration
{
public override void Up()
{
AddColumn("dbo.JobsRecordHistories", "FileContent", c => c.Binary());
AddColumn("dbo.JobsRecords", "FileContent", c => c.Binary());
}
public override void Down()
{
DropColumn("dbo.JobsRecords", "FileContent");
DropColumn("dbo.JobsRecordHistories", "FileContent");
}
}
并且在 运行 之后失败并显示一条非常不清楚的消息:update-database -verbose:
PM> Update-Database -verbose
Using StartUp project 'JobsManager'.
Using NuGet project 'TasksJobsLib'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'SchedulerJobs' (DataSource: 172.20.101.236, Provider: MySql.Data.MySqlClient, Origin: Configuration).
Applying explicit migrations: [201512141437137_FileContentByteArray].
Applying explicit migration: 201512141437137_FileContentByteArray.
alter table `JobsRecordHistories` add column `FileContent` longblob
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.6.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.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
我昨天成功添加了迁移...我还尝试将新的 属性 设置为可空,并将 null 作为默认值,但它没有用。
我在 JobsRecords 中有约 300K 条记录,在 JobsRecordHistories 中有约 600K 条记录,所以我想这可能与它需要做的大量更新有关,从而导致超时?
更新:现在我看到新列确实已添加到我的表中!这是最糟糕的事情,因为现在代码和数据库都不是最新的!!
任何人都可以阐明更新失败的原因、成功更改表格的原因以及现在正确的做法是什么?
谢谢!
好的,解决了:
一种。我在配置部分更改了迁移操作的超时时间:
internal sealed class Configuration : DbMigrationsConfiguration<TasksJobsLib.TasksJobsDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = false;
**CommandTimeout = 200;**
}
protected override void Seed(TasksJobsLib.TasksJobsDbContext context)
{
//nothing
}
}
b。当我尝试将新添加的 byte[] 设置为可空且默认值为 null 时,此更改不起作用。不知道为什么。
c。我仍然不喜欢 update-database 命令的输出消息。它根本没有显示有用的详细信息!
我一直在项目中使用 EF 6.0 CodeFirst 并成功添加了一些迁移,但现在我有一个我无法应用的新迁移。这是脚手架迁移:
public partial class FileContentByteArray : DbMigration
{
public override void Up()
{
AddColumn("dbo.JobsRecordHistories", "FileContent", c => c.Binary());
AddColumn("dbo.JobsRecords", "FileContent", c => c.Binary());
}
public override void Down()
{
DropColumn("dbo.JobsRecords", "FileContent");
DropColumn("dbo.JobsRecordHistories", "FileContent");
}
}
并且在 运行 之后失败并显示一条非常不清楚的消息:update-database -verbose:
PM> Update-Database -verbose
Using StartUp project 'JobsManager'.
Using NuGet project 'TasksJobsLib'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'SchedulerJobs' (DataSource: 172.20.101.236, Provider: MySql.Data.MySqlClient, Origin: Configuration).
Applying explicit migrations: [201512141437137_FileContentByteArray].
Applying explicit migration: 201512141437137_FileContentByteArray.
alter table `JobsRecordHistories` add column `FileContent` longblob
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.6.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.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
我昨天成功添加了迁移...我还尝试将新的 属性 设置为可空,并将 null 作为默认值,但它没有用。 我在 JobsRecords 中有约 300K 条记录,在 JobsRecordHistories 中有约 600K 条记录,所以我想这可能与它需要做的大量更新有关,从而导致超时?
更新:现在我看到新列确实已添加到我的表中!这是最糟糕的事情,因为现在代码和数据库都不是最新的!!
任何人都可以阐明更新失败的原因、成功更改表格的原因以及现在正确的做法是什么?
谢谢!
好的,解决了:
一种。我在配置部分更改了迁移操作的超时时间:
internal sealed class Configuration : DbMigrationsConfiguration<TasksJobsLib.TasksJobsDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = false;
**CommandTimeout = 200;**
}
protected override void Seed(TasksJobsLib.TasksJobsDbContext context)
{
//nothing
}
}
b。当我尝试将新添加的 byte[] 设置为可空且默认值为 null 时,此更改不起作用。不知道为什么。
c。我仍然不喜欢 update-database 命令的输出消息。它根本没有显示有用的详细信息!