C# 实体Framewok使用二进制数组添加迁移失败
我一直在一个项目上使用EF 6.0 CodeFirst,并成功地添加了一些迁移,但现在我有一个新的迁移,我无法应用。以下是脚手架迁移:C# 实体Framewok使用二进制数组添加迁移失败,c#,mysql,entity-framework,entity-framework-6,entity-framework-migrations,C#,Mysql,Entity Framework,Entity Framework 6,Entity Framework Migrations,我一直在一个项目上使用EF 6.0 CodeFirst,并成功地添加了一些迁移,但现在我有一个新的迁移,我无法应用。以下是脚手架迁移: public partial class FileContentByteArray : DbMigration { public override void Up() { AddColumn("dbo.JobsRecordHistories", "FileContent", c => c.Binary());
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'.
PM>更新数据库-详细
正在使用启动项目“JobsManager”。
使用NuGet项目“TasksJobsLib”。
指定'-Verbose'标志以查看应用于目标数据库的SQL语句。
目标数据库是:“SchedulerJobs”(数据源:172.20.101.236,提供程序:MySql.Data.MySqlClient,源:配置)。
应用显式迁移:[201512141437137_FileContentByteArray]。
正在应用显式迁移:201512141437137_FileContentByteArray。
alter table`JobsRecordHistories`add column`FileContent`longblob
System.Runtime.Serialization.SerializationException:未解析成员“MySql.Data.MySqlClient.MySqlException,MySql.Data,版本=6.9.6.0,区域性=中性,PublicKeyToken=c5687fc88969c44d”的类型。
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处
位于System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner)
位于System.Data.Entity.Migrations.Design.ToolingFacade.Update(字符串targetMigration,布尔力)
在System.Data.Entity.Migrations.UpdateDatabaseCommand.c__DisplayClass2.b__0()中
位于System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(操作命令)
未解析成员“MySql.Data.MySqlClient.MySqlException,MySql.Data,Version=6.9.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d”的类型。
我昨天已成功添加迁移。。。我还尝试将新属性设置为nullable,默认值为null,但没有成功。
我在JobsRecords和JobsRecordHistory中分别有约300K和约600K条记录,所以我想这可能与它需要进行的大量更新有关,因此会超时
更新:现在我看到新列确实添加到了我的表中!这是最糟糕的事情,因为现在的代码和数据库不是最新的
有谁能解释一下更新失败的原因、成功更改表的原因以及现在正确的做法是什么
谢谢 好的,解决了:A.我在配置部分更改了迁移操作的超时:
internal sealed class Configuration : DbMigrationsConfiguration<TasksJobsLib.TasksJobsDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = false;
**CommandTimeout = 200;**
}
protected override void Seed(TasksJobsLib.TasksJobsDbContext context)
{
//nothing
}
}
内部密封类配置:dbmigtorinsconfiguration
{
公共配置()
{
AutomaticMiggerationsEnabled=假;
AutomaticMigrationDataLossAllowed=false;
**CommandTimeout=200**
}
受保护的覆盖无效种子(TasksJobsLib.TasksJobsDbContext上下文)
{
//没什么
}
}
b。当我尝试将新添加的字节[]设置为可空且默认值为空时,此更改无效。我不知道为什么
c。我仍然不喜欢updatedatabase命令的输出消息。它没有显示任何有用的细节