【问题标题】:Entity Framewok Failed adding migration with binary array实体框架无法使用二进制数组添加迁移
【发布时间】:2016-03-20 03:26:21
【问题描述】:

我一直在项目中使用 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 有大约 30 万条记录,在 JobsRecordHistories 有大约 60 万条记录,所以我想这可能与它需要做的大量更新有关,因此会超时?

更新:现在我看到新列确实已添加到我的表中!这是最糟糕的事情,因为现在代码和数据库不是最新的!

谁能解释一下更新失败的原因、成功更改表的原因以及现在的正确做法是什么?

谢谢!

【问题讨论】:

    标签: c# mysql entity-framework entity-framework-6 entity-framework-migrations


    【解决方案1】:

    好的,解决了:
    一种。我在配置部分更改了迁移操作的超时时间:

    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 命令的输出消息。它根本没有显示任何有用的细节!

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多